[英]Sencha ajax call to php file
I'm both a sencha and ajax newbie. 我既是sencha又是ajax新手。 I'm trying to return some data from a php file that connects to a mysql server. 我正在尝试从连接到mysql服务器的php文件返回一些数据。 I'm triggering an ajax request when I press a button. 当我按下一个按钮时,我正在触发一个ajax请求。
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....... 我的getpoi php文件代码如下........
<?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. php文件之所以起作用,是因为如果我在文件本身中将set poiid更改为3并在浏览器中将其打开,则会得到该位置。 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. 但是,如果我通过该按钮在sencha应用程序中调用它,则控制台会正确记录“服务器ping”,但会记录“未定义”而不是坐标。 Any ideas what I'm doing wrong? 有什么想法我做错了吗?
Thanks in advance A 在此先感谢
it look like you ajax is not sending the request right. 看来您ajax没有正确发送请求。 Try this: 尝试这个:
setInterval(function(){
console.log("Server pinged");
myRequest = Ext.Ajax.request({
url: 'http://localhost/getpoi.php?poiid=3',
method: 'GET',
callback: function(response) {
console.log(response.responseText);
}
});
to be sure that is loading press F12, go to Network and look the requests. 为确保正在加载,请按F12,转到“网络”并查看请求。 ;) (Firebug or Inspect Element on Chrome) ;)(Chrome上的Firebug或Inspect Element)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.