我有以下代码:
$.ajax({ type: 'POST',
url: 'index.jsp',
data: 'id=111',
dataType: 'jsonp',
success: function(data) {
alert(data.result);
},
error: function( err1, err2, err3 )
{
alert('Error:' + err3 )
}
});
我将响应作为由json参数生成的回调参数返回,像这样:
jQuery16105097715278461496_1314674056493({"result" : "success"})
这在FF中是可以的,但是在IE 9中,它会转到错误功能并显示:
"Error: jQuery16105097715278461496_1314674056493 was not called" .
F12上有一条警告:
SEC7112: Script from http://otherdomain.com
index.jsp?callback=jQuery16105097715278461496_1314674056493
&eid=111&_=1314674056493
was blocked due to mime type mismatch
try adding a contentType
$.ajax({
type: 'POST',
url: 'index.jsp',
data: {id:'111'},
contentType: "application/json; charset=utf-8",
dataType: 'jsonp',
success: function(data) {
alert(data.result);
},
error: function( err1, err2, err3 )
{
alert('Error:' + err3.status );
alert(err1.responseText);
}
});
here is a good article http://msdn.microsoft.com/en-us/library/gg622941%28v=vs.85%29.aspx
This library is heavenly helpful I found it after wasting a lot hours.
Use this library https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest then you won't need to use jsonp.
And your Cross Site request will begin to work normally.