I’m both a sencha and ajax newbie. I’m trying to return some data from a php file that connects to a mysql server. I’m triggering an ajax request when I press a button.
Here is my sencha code for when the button is pressed……..
onShow: function(){
setInterval(function(){
console.log("Server pinged");
myRequest = Ext.Ajax.request({
url: 'http://localhost/getpoi.php',
method: 'GET',
params: {
poiid: '3'
},
callback: function(response) {
console.log(response.responseText);
}
});
},5000);
},
My getpoi php file code is as follows…….
<?php
$poiid = $_GET["poiid"];
$lat;
$long;
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("murmuration_db", $con);
$result = mysql_query("SELECT * FROM POI WHERE id=$poiid");
while($row = mysql_fetch_array($result))
{
$lat = $row['anchor_geolocation_lat'];
$long = $row['anchor_geolocation_lon'];
}
$response = $lat. ' '. $long;
echo $response;
return $response;
mysql_close($con);
?>
The php file is working because if I change set poiid to 3 in the file itself and open it in the browser, I get the position. But if I call it within the sencha app through the button the console is logging ‘server pinged’ correctly but is logging ‘undefined’ instead of the co-ordinates. Any ideas what I’m doing wrong?
Thanks in advance
A
it look like you ajax is not sending the request right.
Try this:
to be sure that is loading press F12, go to Network and look the requests. 😉
(Firebug or Inspect Element on Chrome)