Connecting Tech Pros Worldwide Help | Site Map

problem in read content file on the server with ajax

Member
 
Join Date: Jan 2009
Posts: 52
#1: Jul 11 '09
hi
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
  1. <html> 
  2.   <head> 
  3.     <title>Ajax at work</title> 
  4.  
  5.     <script language = "javascript">
  6.       var XMLHttpRequestObject = false; 
  7.  
  8.       if (window.XMLHttpRequest) {
  9.         XMLHttpRequestObject = new XMLHttpRequest();
  10.       } else if (window.ActiveXObject) {
  11.         XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
  12.       }
  13.  
  14.       function getData(dataSource, divID) 
  15.       { 
  16.         if(XMLHttpRequestObject) {
  17.           var obj = document.getElementById(divID); 
  18.           XMLHttpRequestObject.open("GET", dataSource); 
  19.  
  20.           XMLHttpRequestObject.onreadystatechange = function() 
  21.           { 
  22.             if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { 
  23.                 obj.innerHTML = XMLHttpRequestObject.responseText; 
  24.             } 
  25.           } 
  26.  
  27.           XMLHttpRequestObject.send(null); 
  28.         }
  29.       }
  30.     </script>
  31.   </head> 
  32.  
  33.   <body>
  34.  
  35.     <H1>Fetching data with Ajax</H1>
  36.  
  37.     <form>
  38.       <input type = "button" value = "Display Message" onclick = "getData('data.txt', 'targetDiv')"> 
  39.     </form>
  40.  
  41.     <div id="targetDiv">
  42.       <p>The fetched data will go here.</p> 
  43.     </div> 
  44.  
  45.   </body> 
  46. </html>
my browser is internet explorer 4.0
and i run this script on windows NT 5.1
thanks very much
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Jul 12 '09

re: problem in read content file on the server with ajax


Quote:

Originally Posted by oranoos3000 View Post

my browser is internet explorer 4.0

are you sure that IE 4 actually supports AJAX? I mean, IE 6 is still a programmer's nightmare but IE 4… that's more than 10 years ago (and personally I didn't expect it to be used any more)
Reply


Similar JavaScript / Ajax / DHTML bytes