简体   繁体   中英

jQuery JSONP not working anymore?

I have been trying to load a JSON file from a cross-domain server. I've tried examples from stackoverflow and from the 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. 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/

Content-Type:application/javascript

rather than Content-Type:application/json;

Could it be because your file is named .js , that Apache is serving the content type itself?

Try changing the file type, to JSON and setting up Apache to serve that filetype with the correct MimeType.

I found this using Fiddler - A HTTP Debugger.. open Fiddler(2), make your request in your browser and Fiddler2 then picks it up. From there, just checked the response for your file.

在此处输入图片说明 It looks like your server is returning the response as "Application/Javascript"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM