Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top