2

This AJAX code is working in IE10+ and Chrome and another browser, but it is not working in IE8 and IE9.

<table id="table" border="1"> 
    <tbody style="display: table-row-group"></tbody>
</table>

jQuery(document).ready(function(){
    $.support.cors = true;

    var url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22EURUSD%22%2C%20%22CADUSD%22%2C%20%22GBPUSD%22%2C%20%22AEDUSD%22%2C%20%22TRYUSD%22%2C%20%22RUBUSD%22%2C%20%22INRUSD%22%2C%20%22SARUSD%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=";

    var $tbody = $('#table').find('tbody');
    var $thead = $('#table').find('thead');

    $.ajaxSetup({ cache: false });

    $.ajax({
        crossDomain: true,
        type: "GET",
        url: url,
        cache: false
    }).done(function (data) {
        alert("lev 2 ");
        var ObjectKeys = Object.keys(data.query.results.rate[0]);
        var row = "<tr>";
        row += "</tr>";
        $thead.append(row);

        $.each(data.query.results.rate, function (i, el) {
            console.log("lev 3 = " + i);
            $tbody.append($('<tr />').append($('<td />').text(el.id)).append($('<td />').text(el.Name)).append($('<td />').text(el.Rate)).append($('<td />').text(el.Ask)).append($('<td />').text(el.Bid)));
        });
    });        
});

How can I solve this problem?

DEMO Fiddle Here

Ash
  • 2,108
  • 2
  • 17
  • 22
Aman Feyzi
  • 35
  • 5
  • 1
    http://stackoverflow.com/questions/17298808/cross-domain-jquery-ajax-not-working-in-ie9 Please check this post. – Sudipta Kumar Maiti Oct 29 '15 at 07:40
  • 1
    When you say "not working", what do you mean? Error message in console? Request timing out? Nothing happends? Request returns error? – Anders Oct 29 '15 at 07:59

1 Answers1

1

The issue is IE8 doesn't support the Cross Origin Resource Sharing (CORS) XHR, so you can't do a cross domain ajax call with the native XHR or jQuery's $.ajax.

For IE8, Microsoft decided to come up with their own cross domain XHR instead of using the CORS XHR, which is called XDomainRequest, so you'll have to implement that to support IE8 users. An example usage can be found in this answer.

Alternatively, you could proxy the cross domain request through your local server side, making the external request a server to server situation, which won't be subject to Same Origin Policy.

Community
  • 1
  • 1
Akhilesh Singh
  • 1,724
  • 2
  • 19
  • 35