从.json url中提取数据导致Jquery出错

ssj*_*878 2 javascript ajax jquery json

我试图使用一个小脚本来提取数据,我发现它似乎与生成json数据的任何其他url一起工作,但是当我使用它以.json结尾的url时,我只会收到语法错误.

//错误

Uncaught SyntaxError: Unexpected token : http://frontier.ffxiv.com/worldStatus/gate_status.json?callback=jQuery21309476937903091311_1450254419566&q=select+title%2Cabstract%2Curl+from+search.news+where+query%3D%22cat%22&format=json&_=1450254419567
Run Code Online (Sandbox Code Playgroud)

//下面的代码

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script>
// Using YQL and JSONP
$.ajax({
    url: "http://frontier.ffxiv.com/worldStatus/gate_status.json",

    // The name of the callback parameter, as specified by the YQL service
    jsonp: "callback",

    // Tell jQuery we're expecting JSONP
    dataType: "jsonp",

    // Tell YQL what we want and that we want JSON
    data: {
        q: "select title,abstract,url from search.news where query=\"cat\"",
        format: "json"
    },

    // Work with the response
    success: function( response ) {
        console.log( response ); // server response
    }
});
</script>
Run Code Online (Sandbox Code Playgroud)

ade*_*neo 5

您正在执行ajax请求的URL不提供JSONP,只是常规JSON.

你得到一个解析错误,因为结果是这样的

{"status":0}
Run Code Online (Sandbox Code Playgroud)

虽然jQuery期望类似的东西

callback({"status":0})
Run Code Online (Sandbox Code Playgroud)

不幸的是,它看起来也不支持CORS,因此由于同源策略,无法从客户端获取该URL的数据.