i have a script that with click a button in this script text with id="targetDiv"
is substitute with content of the file data.txt.
this script and data.txt are on the same directory on my local disk
my problem is that with pressing button on this script this is not substituted
and XMLHttpRequestObject.status instead of 200 is 0
what is meaning of XMLHttpRequestObject.status instead equal to zero?
how can i change XMLHttpRequestObject.status to 200?
my script is:
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <title>Ajax at work</title>
- <script language = "javascript">
- var XMLHttpRequestObject = false;
- if (window.XMLHttpRequest) {
- XMLHttpRequestObject = new XMLHttpRequest();
- } else if (window.ActiveXObject) {
- XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
- }
- function getData(dataSource, divID)
- {
- if(XMLHttpRequestObject) {
- var obj = document.getElementById(divID);
- XMLHttpRequestObject.open("GET", dataSource);
- XMLHttpRequestObject.onreadystatechange = function()
- {
- if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
- obj.innerHTML = XMLHttpRequestObject.responseText;
- }
- }
- XMLHttpRequestObject.send(null);
- }
- }
- </script>
- </head>
- <body>
- <H1>Fetching data with Ajax</H1>
- <form>
- <input type = "button" value = "Display Message" onclick = "getData('data.txt', 'targetDiv')">
- </form>
- <div id="targetDiv">
- <p>The fetched data will go here.</p>
- </div>
- </body>
- </html>
and i run this script on windows NT 5.1
thanks very much