Json returns 'null'

I am currently using Phonegap with xcode to create an iPhone application.

I'm just trying to just call Json to get a query from a database (php) and it returns Null.

I have a domain whitelist in a .plist file for a phone call. Here is the m code:

    $.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 code:

<?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)


?>

If you run only the php file, it will display the correct results.

Thank your help.

Thank.

+3
source share
2 answers

Try replacing the first line:

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

:

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

It looks like you have problems with url '"http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php",'should be "http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php"I think

0
source

All Articles