AJAX Jsonp Error in IE9

I have the following code

$.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 ) } }); 

I am returning the response as a callback parameter created using the json argument. like this

 jQuery16105097715278461496_1314674056493({"result" : "success"}) 

This works great in FF. In IE 9, it goes into error function and shows

 "Error: jQuery16105097715278461496_1314674056493 was not called" . 

when i see f12. I see a warning saying.

 SEC7112: Script from http://otherdomain.com index.jsp?callback=jQuery16105097715278461496_1314674056493 &eid=111&_=1314674056493 was blocked due to mime type mismatch 

enter image description here

enter image description hereenter image description here

+4
source share
2 answers

try adding 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

+1
source

This library is very useful, I found it after repeated waste.

Use this library https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest , then you will not need to use jsonp.

And your cross site request will start working fine.

0
source

Source: https://habr.com/ru/post/1369600/


All Articles