Note that there are some explanatory texts on larger screens.

plurals
  1. POcall javascript function from AJAX php file isn't working
    primarykey
    data
    text
    <p>SOLVED! I used only javascript to the task. Now it reads the text from the php and use the coordinates. </p> <pre><code> var texto = HttpReq.responseText; var lats,lons; var pos = texto.search(' '); lats = texto.substring(0,pos-1); lons = texto.substring(pos+1); </code></pre> <p>Thank you all! You are wonderful!</p> <hr> <p>My site has a main page, where after the user selects a city, I wanna show it on a google map. The coordinates of the cities are in a table, so I'm using php in a separate .php file, accessed through AJAX. In the separate .php, I want to call a JS function from the main page to add the point to the map (the JS map object was on the main page, I also tried to put all the JS in a .js file, but the function still isn't called at all (I'm using FireBug to breakpoint it, but the function is never called).</p> <p>The result from AJAX's GET is this:</p> <pre><code>Latitude: -21.15361&lt;BR&gt;Longitude: -41.567501&lt;BR&gt;&lt;script src="functions.js" type="text/javascript"&gt;addPoint(-21.15361,-41.567501);&lt;/script&gt; </code></pre> <p>The Latitude and Longitude appears on screen, but the method addPoint ain't called. Am I missing something stupid here? Thanks in advance.</p> <p>-- EDIT -- OK, here's what I'm trying to do (that's inside getcoords.php, the file called thru ajax):</p> <pre><code>$stmt = $dbh-&gt;prepare("select id_mun,lat,lon from municipio where id_mun = '".$_GET['mun']."'"); if ($stmt-&gt;execute()) { echo '&lt;script src="functions.js" type="text/javascript"&gt;&lt;/script&gt;'; while ($row = $stmt-&gt;fetch(PDO::FETCH_BOTH)) { echo "Latitude: $row[1]&lt;BR&gt;"; echo "Longitude: $row[2]&lt;BR&gt;"; echo '&lt;script type="text/javascript"&gt;'; echo 'alert("testando");'; echo "addPoint($row[1],$row[2]);"; echo "&lt;/script&gt;"; } } </code></pre> <p>and the result that goes to the innerHtml from my div (and is not executed):</p> <pre><code>&lt;script src="functions.js" type="text/javascript"&gt;&lt;/script&gt;Latitude: -15.779722&lt;BR&gt;Longitude: -47.929722&lt;BR&gt;&lt;script type="text/javascript"&gt;alert("testando");addPoint(-15.779722,-47.929722);&lt;/script&gt; </code></pre> <p>Thanks again.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload