If I load a PHP page with Jquery .load(file.php), can the included file use the php variables that were defined on the page that called the load()?
Ajax can do this. Google it, and check out api.jquery.com and look at the ajax functions, .ajax(), .post(), .get(), .load(), etc.
As for your specific question, here is what you would do:
Something like this
You can access associative entries from the PHP
$row array using
var latlng = markers.latlng;
While we're here, you should protect your query from SQL injection. Whilst I always recommend using PDO and parameter binding, a quick fix for you would be
$ref = get_magic_quotes_gpc() ? stripslashes($_GET['ref']) : $_GET['ref']; $sql = sprintf("SELECT * FROM `markers` WHERE `ref` = '%s'", mysql_real_escape_string($ref));
Since you are getting this error as
output started at /fr/game/map.php:1 (note: line 1) I will place money on you having whitespace or a BOM before the opening
<?php tag in
Make sure the opening
< is the first character in the file. If you file is UTF-8, make sure it is UTF-8 without BOM, or convert it to ASCII.
Upon reading the jQuery docs pages for jQuery.get() and jQuery.load(), the callback argument is quoted as the following:
"A callback function that is executed if the request succeeds."
Let me stress the terms "request" and "succeeds". The request may succeed, but that does not mean that the content is loaded. Same problem as
.load() — the functions aren't built the way I was thinking.
If I want to trigger an event once the new content finally loads, I'll need to take a different approach.
- I could use the JS
onloadevent, and trigger it by completely replacing an HTML element (having the replaced code contain an
onloadproperty). EDIT: Note that using HTML
iframeelements is pretty awful, primitive, and "clunky". I just need to find a better way to trigger a function as soon as loading the new content finishes.
- Also, I could use jQuery to check the
.ready()state of new content, but ("AFAIK" / as far as I know) that will only work if the checked content is a new HTML element, not a preexisting HTML element whose interior content is changed. The jQuery
.ready()status of any preexisting element will (AFAIK) already be shown as "ready" despite if new content is loading. Perhaps I am wrong about this, and I would like to be corrected if so.
Unless otherwise notified, this answer will be marked as the correct one. The original question was mistaken that
.load() was all I needed. Cheers!
You're misunderstanding how things work.
Does that make sense?