从.json url中提取数据导致Jquery出错
Pulling data from .json url causing error with Jquery
我正在尝试使用一个小脚本来提取数据,我发现这个脚本似乎可以与任何其他生成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
//低于的代码
<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>
您进行ajax请求的URL不提供JSONP,只提供常规JSON。
你会得到一个解析错误,因为结果类似于
{"status":0}
而jQuery期望类似的东西
callback({"status":0})
不幸的是,看起来也不支持CORS,因此由于同源策略,无法从客户端获取该URL中的数据。
相关文章:
- 将javascript代码转换为jquery代码时出错
- jQuery AJAX总是出错
- 在Laravel 5中使用JQuery从href提取值时出错
- 如何在jquery中检查null值而不出错
- Jquery Mobile 中的翻转开关出错
- 在使用 jQuery printElement 插件时出错
- 不允许的关键字符.通过 Codeigniter 中的 jQuery 在帧中加载嵌入代码时出错
- 在jquery中获取值时出错
- Jquery日期选择器验证出错
- 加载Jquery时Chrome扩展出错
- jQuery AJAX POST请求传递值时出错
- jQuery position()/offset()值在重载时出错(chrome)
- 404调用jQuery.post时出错
- 将jquery ajax请求推入数组时出错
- jQuery$(document).ready阻塞页脚脚本时出错
- 使用JQuery将XML解析为SQLite DB时出错:所有行都具有相同的值
- 使用selenium实现jquery时出错
- JQuery尝试进行Ajax调用时出错
- 从.json url中提取数据导致Jquery出错
- Jquery出错,速度变慢