weixin_33696106 2016-02-13 23:25 采纳率: 0%
浏览 344

PHP JSON返回\ u0000

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?

  • 写回答

1条回答 默认 最新

  • weixin_33749242 2016-02-14 10:50
    关注

    PHPStorm killed my code, it added a ton of NULL text after the end of my code, this was not viewable in PHPStorm, but when I opened the file in Sublime text editor it showed me the NULL text/tags..

    评论

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: