Jquery Ajax, not working in Internet explorer

前端 未结 2 1258
小鲜肉
小鲜肉 2020-12-20 04:03

I\'m trying to do some jQuery ajax and it works in Firfox and Chrome, but not in internet explorer 9.

The final code will have to go across sub-domains, and this doe

相关标签:
2条回答
  • 2020-12-20 04:13

    Here's the solution I went with after about a day of struggling with this inconsistency...

    // new method as to not overwrite jQuery's defaults
    var cors = (window.XDomainRequest) ? function(url, callback) {
    
        var xdr = new XDomainRequest();
        xdr.open('get', url);
        xdr.onload = function() { callback(xdr.responseText); }
        xdr.send();
    
    } : $.get; // else, use jQuery's method
    

    Use...

    cors(url, function(msg) { alert(msg); }); // pretty well same as $.get
    

    Copy and paste, this of course doesn't serve all purposes, but it's a start and it works.

    0 讨论(0)
  • 2020-12-20 04:23

    On the http://services.whygo.net/sendAjax2.html page, I see that you've got the expected dataType of the AJAX response coming back from the server as JSON, but the response actually comes back as a plain text string ("Email successfully sent.").

    Perhaps you could try commenting out dataType and let jQuery figure out what type of response comes back.

    0 讨论(0)
提交回复
热议问题