2

I'm using following code in one of my JavaScript file.

xhr = new XMLHttpRequest();
xhr.open("GET", dest, true); // dest is the URL
xhr.onreadystatechange = checkData;
xhr.send(null);

But when I run the script in IE,m it is giving me following error.

SCRIPT5: Access is denied.

Then I thought to check the browser type and execute a separate code for IE like below.

if(isIE){
    xhr = new XDomainRequest(); 
    xhr.onerror = function (res) { alert("error: " + res); };
    xhr.ontimeout = function (res) { alert("timeout: " + res); };
    xhr.onprogress = function (res) { alert("on progress: " + res); };
    xhr.onload = function (res) { alert("on load: " + res); };
    xhr.timeout = 5000;
    xhr.open("get", dest); // Error line
    xhr.send(json);
}

But again it is giving me the same error where I have used following code

xhr.open("get", dest);

At the end I want to call checkData function like I have done below with other browsers.

xhr.onreadystatechange = checkData;

What have I missing there to get Access Denied error at the IE console?

AnujAroshA
  • 4,623
  • 8
  • 56
  • 99
  • check this one, its related to your question: http://stackoverflow.com/questions/22098259/access-denied-in-ie-10-and-11-when-ajax-target-is-localhost – Savaratkar Sep 25 '15 at 19:19

1 Answers1

0

Try below.. It worked for me in IE8 and IE9.

 if ($.browser.msie && window.XDomainRequest) {
                // Use Microsoft XDR
               var xdr = new XDomainRequest();
               xdr.open("get", serviceURL+'GetItem/50000');
               xdr.onload = function() {
                    //parse response as JSON
                   var response1 = $.parseJSON(xdr.responseText);
                   if (response1 == null || typeof(response1) == 'undefined') {
                        var result = $.parseJSON(data.firstChild.textContent);
                        alert(result);
                    } else {
                        $(response1.ResultData).each(function(i, item) {
                            alert(item.BorrName.toString());
                        });
                    }
                 };
               xdr.send();
               xdr.onerror = function(errormsg) {
                            alert('in error');
                 };
            }

Service looks like below

[OperationContract]
        [WebGet(UriTemplate = "GetItem/{itemnumber}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
        ItemEntity GetItem(string itemnumber);
sharp_net
  • 737
  • 2
  • 5
  • 12