我有以下代码
$.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"})
"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
解决方法
尝试添加contentType
$.ajax({ type: 'POST',data: {id:'111'},contentType: "application/json; charset=utf-8",success: function(data) { alert(data.result); },err3 ) { alert('Error:' + err3.status ); alert(err1.responseText); } });
这是一篇很好的文章http://msdn.microsoft.com/en-us/library/gg622941%28v=vs.85%29.aspx