[英]jQuery JSONP not working anymore?
I have been trying to load a JSON file from a cross-domain server. 我一直在尝试从跨域服务器加载JSON文件。 I've tried examples from stackoverflow and from the jQuery docs.
我已经尝试过stackoverflow和jQuery docs中的示例。 I did get it working in a previous project, but now it strangely does not.
我确实在上一个项目中使它工作,但现在奇怪的是没有。 The error returned from jQuery is unreadable to me.
从jQuery返回的错误对我来说是不可读的。 What can possibly go wrong here?
这里可能出什么毛病?
$(document).ready(function() {
console.log("Start loading");
$.ajax({
type: 'GET',
url: "http://www.nightoferror.nl/data/data.json",
dataType: 'jsonp',
crossDomain: true,
error: function(data) {
console.log('error', data);
},
success: function(data) {
console.log('success', data);
}
});
}); });
And the erratic JSFiddle here: http://jsfiddle.net/ZuyJV/4/ 而不稳定的JSFiddle在这里: http : //jsfiddle.net/ZuyJV/4/
Content-Type:application/javascript
rather than Content-Type:application/json;
而不是
Content-Type:application/json;
Could it be because your file is named .js
, that Apache is serving the content type itself? 可能是因为您的文件名为
.js
,所以Apache本身正在提供内容类型吗?
Try changing the file type, to JSON and setting up Apache to serve that filetype with the correct MimeType. 尝试将文件类型更改为JSON,然后设置Apache以使用正确的MimeType为该文件类型提供服务。
I found this using Fiddler - A HTTP Debugger.. open Fiddler(2), make your request in your browser and Fiddler2 then picks it up. 我使用Fiddler -HTTP调试器找到了它。打开Fiddler(2),在浏览器中发出请求,然后Fiddler2接听它。 From there, just checked the response for your file.
从那里,只需检查文件的响应即可。
It looks like your server is returning the response as "Application/Javascript"
看来您的服务器返回的响应为“ Application / Javascript”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.