jQuery ajax cross
I am trying to make an ajax request using jQuery from my local environment.
$.ajax({
url: requestURL,
dataType: "json",
timeout: 120000,
success: function(data){
// do something
},
error: function(XMLHttpRequest, textStatus, errorThrown){
console.log("Instants.loadGame: error loading games: error text: " + textStatus + "; error thrown: " + errorThrown);
}
});
I have tried using dataType json and jsonp (as that is what everyone else seems to say fixes the problem) but I get errors either way. With dataType json the error response has textStatus = "error" and errorThrown is empty. With dataType jsonp the error response has textStatus = "parsererror" and errorThrown = "jQuery19002007321439859855_1361446807440 was not called".
I know this code works when running on the same domain as my request URL so I can only assume it is because I am doing it on my local environment. I have set my cross-domain.xml to allow everything. I am using jQuery 1.9.0.
Does anyone have any ideas? I have been looking at this a lot online but none of the solutions that helped other people seem to work for me...
Thanks, Heather
When you get an error like "jQuery19002007321439859855_1361446807440 was not called" it's because it's not a correct jsonp response. When using jsonp the server need to be JavaScript (an actual script) and that script needs to call a function which is provided as part of the url (in this case the funciton is named jQuery19002007321439859855_1361446807440 which jQuery maps to the success handler you provided.
Most likely cause is that the server returned plain json data but that won't work. That data need to be passed to the script. So the request to the server should return something like
var data = {"foo":1}; //your data here
jQuery19002007321439859855_1361446807440(data);
链接地址: http://www.djcxy.com/p/47548.html
下一篇: jQuery ajax十字架