2

Possible Duplicate:
SCRIPT5: Access is denied in IE9 on xmlhttprequest

Consider the following HTML code :-

<!-- Check for XMLHttpRequest object in IE 9 -->
<html>
<body>

<script type="text/javascript">
    if(window.XMLHttpRequest){
        alert("XMLHttpRequest supported by browser");
        xhttp = new XMLHttpRequest();
        xhttp.open("GET", "books.xml", false);    <!-- Line 1 -->
        alert("reching??");
        xhttp.send();

    }
    if(window.ActiveXObject){
        alert("ActiveXObject supported by browser");
    }

</script>
</body>
</html>

As per W3C, IE7+ supports XMLHttpRequest object. I am using the same for IE9.

Yes, the object is supported by IE9 as a get the alert for the same. However, XMLHttpRequest's method open is not working. Browser stops at the line 1 shown in the above code.

Why is it so??

I also searched a Microsoft's link. Two different ways of creating XML HTTP Request Object is shown :

  1. xhttp = new XMLHttpRequest;

  2. xhttp = getXMLHttpRequest();

1st way gives the same problem at open method. 2nd way returns a null object. In the same link, I also found that many people are facing the same problem with open method of XMLHttpRequest object in IE but I guess no solution is written there too. :(

Community
  • 1
  • 1
whitehat
  • 2,381
  • 8
  • 34
  • 47
  • That page seems to work on me using IE9 as I get all three alert messages. Are there any messages in the console in the developer tools? (F12 -> Console) – Don Cruickshank Mar 07 '12 at 10:53
  • @DonCruickshank Yes. When I debugged the script, it stops at Line 1. The Console Message is "SCRIPT5: Access is denied." – whitehat Mar 07 '12 at 11:16
  • Moreover, if I call the open method from try-catch block, I can alert the Exception caught. So I guess there is some exception thrown here. – whitehat Mar 07 '12 at 11:17
  • Are you running this page via the `file` or `http` protocol? – Don Cruickshank Mar 07 '12 at 11:25
  • @DonCruickshank: Via File. This is an HTML File in my local machine. And the "books.xml" file is also in the same folder. – whitehat Mar 07 '12 at 11:43

0 Answers0