Ben Thomas
Ben Thomas

Reputation: 87

Json returns 'null'

I am currently using Phonegap along with xcode to make an IPhone App.

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

I have Whitelisted the domain in the .plist file for phonegap. Here is 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 just the php file it displays the correct results.

Would appreciate your help.

Thanks.

Upvotes: 3

Views: 181

Answers (2)

emmgfx
emmgfx

Reputation: 575

Try to replace the first line:

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

to this:

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

Upvotes: 1

Sethunath K M
Sethunath K M

Reputation: 4761

Looks like you are having problem with url '"http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php",' should be "http://slc0013.pickaweb.co.uk/~bengeor1/fixtures.php" I guess

Upvotes: 0

Related Questions