I'm trying to make a JSONP request to allow cross-domain. The situation is that my server DOES NOT handle JSONP request, and it understands this request as JSON and responds back with a JSON object: {result: 1}
Here is my ajax request:
jQuery.ajax({
type : 'POST',
url : "https://example.com/addUser",
data : {
firstName : 'firstName',
lastName : 'lastName',
email : 'email@yopmail.com'
},
crossDomain : true,
jsonpCallback: "jsonpCallback",
success : function(data) {
alert(data);
},
complete : function(jqXHR, textStatus) {
//can do something here
},
error : function (xhr, textStatus, errorThrown) {
if(errorThrown=="jsonpCallback was not called") {
console.log('caught it!');
}
},
dataType : 'jsonp'
});
Readings from the window console:
Resource interpreted as Script but transferred with MIME type text/json: "https://example.com/addUser…Name=firstName&lastName=lastName&email=email%40yopmail.com&_=1359646137496".
Uncaught SyntaxError: Unexpected token :
caught it!
As expected, it throws parseerror exception and I try to handle it. But my question is that since the browser is actually getting the response {result:1}
, can there be a way I could parse it?