Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 599
Ben Thomas Avatar asked May 19 '26 05:05

Ben Thomas


1 Answers

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) {
like image 126
emmgfx Avatar answered May 21 '26 19:05

emmgfx