Pit Digger
Pit Digger

Reputation: 9800

AJAX Jsonp call fails in IE9

I have 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 response as callback parameter generated with argument of json . like this

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

This works absolutely fine in FF . In IE 9 it goes to error function and shows

"Error: jQuery16105097715278461496_1314674056493 was not called" . 

when I see F12 . I see a warning which says .

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 here enter image description here

Upvotes: 4

Views: 6087

Answers (2)

Black Mamba
Black Mamba

Reputation: 15555

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.

Upvotes: 0

Rafay
Rafay

Reputation: 31033

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

Upvotes: 1

Related Questions