When I try to get data from the database via Ajax, PHP returns this:
{"readyState":4,"responseText":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000array(4) {
[\"USR_ID\"]=>
string(1) \"1\"
[\"PLT_ID\"]=>
string(1) \"1\"
[\"NRS.ID\"]=>
string(1) \"1\"
[\"url\"]=>
string(59) \"http://remcocr9.nine.axc.nl/tones/music/ontopoftheworld.mp3\"
}
","status":200,"statusText":"OK"}
This is my PHP code:
<?php
class Playlist
{
public function getPlaylists( $link, $song, $usrid )
{
$playlists = $link->query( "SELECT * FROM TO_PLT WHERE USR_ID = " . $usrid . ";" );
if( $playlists->num_rows ) // 1 or more playlists were found
{
while( $playlist = $playlists->fetch_assoc( ) )
{
// echo an opening DIV containing the playlist name etc via json
$data = $song->getSong( $link, $playlist[ "PLT_ID" ], $usrid);
// echo json_encode($data);
var_dump($data);
// echo json_encode($playlist); // Return playlist data
// echo a closing DIV tag via JSON so the playlist DIV is closed
}
}
else
{
// no playlists were found
}
}
}
?>
And here is the javascript/ajax code that I use to get the data:
function ajaxRequest() {
$.ajax({
type: "GET",
url: hostURL + "users.php",
dataType: 'json'
}).done(function (data) {
console.log(JSON.stringify(data));
}).fail(function (data) {
console.log(JSON.stringify(data));
});
}
The function is called by the Ajax function, how do I get rid of the \u0000
? or is there another error in my code which is causing this?