1

I just started learning Ajax and I am stuck here.

I created 3 files 1. HTML File with code:

<html>
<head>
<script language="javascript" src="../AjaxLearning.js">

</script>
</head>
<body>
<div id="gethelp">
<h3>Text should Change</h3>
</div>
<input type='button' onclick='knowYourBrowser()'
    value='Know Your Browser'>
<input type='button' onclick='loadXMLDoc()' value='Need Help?'>

</body>
</html>
  1. A Text file placed at same directory where the html file is placed text in the file is: I am here to help you

  2. A java script file placed at a location above the html file

    function knowYourBrowser() { alert("I reached here"); var xmlhttp; if(window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); alert ("IE7+, fox, chrome, netscape"); } else { alert ("IE5, 6"); xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } }

    /* Read a text file from the directory*/ function loadXMLDoc() {

    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    
    xmlhttp.onreadystatechange=function()
    {   
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById('gethelp').innerHTML = xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET","Help.txt",true);
    xmlhttp.send(null);
    

    }

but I am getting the below error message

SCRIPT5: Access is denied.

AjaxLearning.js, line 39 character 2

I dont know what I am missing here. Please point out the gaps.

Thanks in Advance Himanshu

Himanshu.MarJAVA
  • 475
  • 1
  • 11
  • 33
  • 1
    http://stackoverflow.com/questions/5793831/script5-access-is-denied-in-ie9-on-xmlhttprequest – marekful Nov 22 '13 at 12:15
  • That's a rather uninformative error message. What browser are you testing with? What if you try with Chrome (making sure to have the developer tools open at the console so you can see errors)? – Quentin Nov 22 '13 at 12:15

1 Answers1

0

Hosted the file on xampp and tried to read the file from the server itself. It worked. Looks like IE has issues reading local resources.

Himanshu.MarJAVA
  • 475
  • 1
  • 11
  • 33