Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i m having a problem with cross domain ajax call
with IE8 and IE9

My below code working fine in Firefox, chrome, IE 10 too
but not working in IE8 and IE9

i spend lot of my time in searching on google but not succeed.

my code is:

$.ajax({
                type: "GET",
                crossDomain: true,
                url: 'MyUrl',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data1) {
			alert(data1);
                },
                error: function (response, textStatus, errorThrown) {
                    alert('not OK ' + response.responseText);
                    alert('not OK ' + textStatus.responseText);
                    alert('not OK ' + errorThrown);
                }
            });


i used this below js also but still not working

<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.1/jquery.xdomainrequest.min.js"></script>

reference : https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest

please help me guys
Posted
Updated 25-Jan-18 1:38am

1 solution

Hello guys i found the answer.
IE9 and lower verstion of IE does not support httpXMLRequest and to solve this problem
we have to make a call by using XDomainRequest.
The answer is below.

C#
if ($.browser.msie && window.XDomainRequest) {
            if (window.XDomainRequest) {
                var xdr = new XDomainRequest();
                var query = 'MyUrl';
                if (xdr) {
                    xdr.onload = function () {
            alert(xdr.responseText);
                     }
                    xdr.onerror = function () { /* error handling here */ }
                    xdr.open('GET', query);
                    xdr.send();
                }
            }
        }
        else {
        $.ajax({
                type: "GET",
                crossDomain: true,
                url: 'MyUrl',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data1) {
            alert(data1);
                },
                error: function (response, textStatus, errorThrown) {
                    alert('not OK ' + response.responseText);
                    alert('not OK ' + textStatus.responseText);
                    alert('not OK ' + errorThrown);
                }
            });
    }



thats it.

One more thing if your data is not showing properly on page then set your
document mode as standard so IE will use its maximum capacity of supports.
other browsers are so intelligent so no need to explain more here.
To set document mode standard just put below line in header part of your page.

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />


VB
it will work in IE7, IE8 and IE9, IE10 supports all the things so no need to put this.

you can also find solution here.

http://www.kailashtandel.com/2014/01/call-wcf-restful-service-from-cross.html

Enjoy Scripting...
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900