3

我目前正在使用 Phonegap 和 xcode 来制作 iPhone 应用程序。

我只是在尝试一个简单的 Json 调用来从数据库(php)获取查询,它返回 Null。

我已将 .plist 文件中的域列入 phonegap 的白名单。这是m代码:

    $.getJSON('"http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php",', function(data) {
        alert(data); //uncomment this for debug
        //alert (data.item1+" "+data.item2+" "+data.item3); //further debug
        $('#resultLog').html("<p>item1="+data.id+" item2="+data.home_team+" item3="+data.away_team+"</p>");
    });

PHP代码:

<?php
 header("Access-Control-Allow-Origin: *");
ini_set('display_errors',1); 
 error_reporting(E_ALL);


 // Set your return content type
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');

$db = "localhost";
$db_name = "xxx";
$db_user = "xxx";
$db_pwd = "xxxx";

$con = mysql_connect($db, $db_user, $db_pwd);
if (!$con) {
     $status = 11; //database error
}

$db_selected = mysql_select_db($db_name, $con);
     if (!$db_selected) {

}

$query = "SELECT * FROM Fixtures";
$result = mysql_query($query);

mysql_close();

$num = mysql_numrows($result);


$rows = array();
while($r = mysql_fetch_assoc($result)) {
  $rows[] = $r;
}

echo json_encode($rows)


?>

如果您只运行 php 文件,它会显示正确的结果。

感谢您的帮助。

谢谢。

4

2 回答 2

1

尝试替换第一行:

$.getJSON('"http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php",', function(data) {

对此:

$.getJSON("http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php", function(data) {
于 2012-05-06T18:12:23.870 回答
0

看起来你的 url 有问题我猜'"http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php",'应该是"http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php"

于 2012-05-06T18:06:55.170 回答