Using $.getJSON to perform cross domain request problem
I'm using the following code to make cross domain request using $.getJSON, request completed but with errors, I cannot exactly detect what is the thrown error.
Based on callback param of request value I route it to a certain method which retrieves required JSON data.
$.getJSON("http://wthsrvr:45452/Handler.ashx/?Callback=DocumentReadStatus",
{
userID: vuserID,
documentID: vdocumentID,
format: "json"
},
function(result) {
if (result.readStatus == '1') {
alert("ACCEPTED");
}
else if (result.readStatus == '0') {
alert("NOT ACCEPTED");
}
else {
alert(result.readStatus);
}
});
FYI: while development of this locally, everything worked fine, but after solution deployment to server and trying to do the same, I got that problem.
Also, I tried the same functionality with web service, I got the same problem while calling web service from server.
I'm using ajaxSetup to detect thrown errors.
$.ajaxSetup({ "error": function(XMLHttpRequest, textStatus, errorThrown) {
alert("textStatus: " + textStatus);
alert("errorThrown: " + errorThrown);
alert("re开发者_Go百科sponseText: " + XMLHttpRequest.responseText);
}
});
To access across different website, you have to use JSONP, which actually becomes a request of a JavaScript file and the data is sent back as part of the JavaScript file.
Actually, it was a permission issue. Using "Access-Control-Allow-Origin" HTTP header so that the resource can be accessed by any domain in a cross-site manner.
Check the following MDN article for this.
精彩评论