Jquery Phonegap Json请求
我目前正在phonegap中制作IPhone应用程序 我目前正在使用json请求服务器端php的一些db细节,并输出结果 当我直接将应用程序运行到浏览器中,但不是从IPhone模拟器中运行时,它就能工作 我已经在php中添加了allow access*,并在xcode中将该域列为白名单 你知道这是什么问题吗 jquery的代码片段:Jquery Phonegap Json请求,jquery,iphone,cordova,Jquery,Iphone,Cordova,我目前正在phonegap中制作IPhone应用程序 我目前正在使用json请求服务器端php的一些db细节,并输出结果 当我直接将应用程序运行到浏览器中,但不是从IPhone模拟器中运行时,它就能工作 我已经在php中添加了allow access*,并在xcode中将该域列为白名单 你知道这是什么问题吗 jquery的代码片段: $.getJSON("http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php", functio
$.getJSON("http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php",
function(data) {
$.each(data.userdata, function(i,user){
var tblRow =
"<p>"+user.hometeam
+user.awayteam+"</p>"
$(tblRow).appendTo("#fixtures_acc");
//alert (data.item1+" "+data.item2+" "+data.item3); //further debug
$('#resultLog').html(tblRow);
});
});
PHP:
非常感谢。不要像使用字符串函数那样创建JSON。改为创建一个数组,echo json_encode$array;您可以检查一下,当您请求一个static.JSON文件时,它是否在应用程序中工作。
$query = "SELECT * FROM Fixtures";
$result = mysql_query($query);
mysql_close();
echo '{
"userdata": [';
for ($count=0; $count <= mysql_numrows($result); $count++) {
echo '{';
$id = mysql_result($result, $count, "id");
$name = mysql_result($result, $count, "home_team");
$awayteam = mysql_result($result, $count, "away_team");
echo "\"hometeam\" : \"$name\", \"awayteam\" : \"$awayteam\"";
echo '}';
if(mysql_numrows($result) != $count){echo ',';}
}
echo ']
}';