PHP JSON Returns u0000

PHP JSON Returns u0000

本文关键字:u0000 Returns JSON PHP      更新时间:2023-09-26

当我尝试通过Ajax从数据库中获取数据时,PHP返回以下内容:

{"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) {'n  ['"USR_ID'"]=>'n  string(1) '"1'"'n  ['"PLT_ID'"]=>'n  string(1) '"1'"'n  ['"NRS.ID'"]=>'n  string(1) '"1'"'n  ['"url'"]=>'n  string(59) '"http://remcocr9.nine.axc.nl/tones/music/ontopoftheworld.mp3'"'n}'n","status":200,"statusText":"OK"}

这是我的PHP代码:

<?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
            }
        }
    }
?>                               

这是我用来获取数据的javascript/ajax代码:

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));
});
}

该函数由 Ajax 函数调用,如何摆脱'u0000? 还是我的代码中有另一个错误导致这种情况?

PHPStorm 杀死了我的代码,它在我的代码结束后添加了大量 NULL 文本,这在 PHPStorm 中是看不到的,但是当我在 Sublime 文本编辑器中打开文件时,它向我显示了 NULL 文本/标签。