Tito
Tito

Reputation: 9044

Cross domain ajax jsonp request not working in IE8

Using jquery-1.9.1 , I have enabled CORS support.

$.support.cors = true;

Then I am making an ajax request as shown below, I have also enabled jsonp callback support from the server side.

$.ajax({
            type: 'GET',
            url: url,
            async: false,
            contentType: "application/json",
            jsonpCallback: 'jsonCallback',
            dataType: 'json',
            success: function(data) {
               var featureJSON = data.feature;

            },
            error: function(e) {

            },
            complete: function () {

            }
        });

I have deployed this in jboss and accessed the page from another computer(different domain/ip address ) . This ajax call works in FF and Chrome from another computer and in the same computer.

It also works in IE , but in the same computer.

Will not work in IE when accessed from some other computer other than the one I deployed in.

After googling around , I understood that IE* do not allow cross domain ajax calls which is made by jquery.And jquery do not support IE's XDomain object.

To conclude , how do I make jquery use IE's XDomain object ? , I have almost completed the app ( my bad , I didnt check the XDomain thing ) . I cannot rebuild the code again. Is there any other solution ?

Upvotes: 0

Views: 4131

Answers (1)

David Fregoli
David Fregoli

Reputation: 3407

you can't "enable" CORS...$.support is supposed to be a ready only table of what the current browser supports. Changing false values to true doesn't magically add unsupported features to old browsers!

if ($.support.cors) {
// your code
} else {
    $.ajax({
        type: 'GET',
        url: url,
        dataType: 'jsonp',
        data: {
          callback : '?'
        },
        success: function(data) {
           var featureJSON = data.feature;

        },
        error: function(e) {

        },
        complete: function () {

        }
   });
}

Upvotes: 2

Related Questions