jquery json function returning null
Posted
by ian
on Stack Overflow
See other posts from Stack Overflow
or by ian
Published on 2010-06-14T06:42:28Z
Indexed on
2010/06/14
6:52 UTC
Read the original article
Hit count: 189
I have a jquery script as below:
$.ajax({
type: "GET",
url: "http://www.site.com/v4/ajax/get_song_info.php",
data: ({id : song_id }),
dataType: "json",
success: function(data)
{
alert( "Data: " + data );
}
});
And the associated php page:
<?php
include_once '../connect.php';
$song_id = $_GET['id'];
$query = mysql_query("SELECT * FROM songs WHERE id = '$song_id' LIMIT 1");
$song = mysql_fetch_row($query);
$song_info = array( htmlentities($song[3]) , htmlentities($song[4]) );
header('Content-Type: application/json');
echo json_encode($song_info);
?>
The php returns something like this when I call it on its own in a browser: ["Peaches","I Feel Cream (Proxy Remix)"]
However when I make the jQuery call my alert shows 'Data: null'
© Stack Overflow or respective owner