If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

hi guys need help with a simple ajax script please

i need the simplest way to add to my javascript code a way of getting data from a text file in the same directory as the index.html and putting the data into a variable called data1 to be used by the rest of the script
any ideas

Yes, you did not use my example above. Instead you removed the (important) callback onreadystatechange and treated the responseText from an asynchronous request (third parameter of open is true) as if it was a synchronous one ... which obviously doesn't work. Additionally, starting from IE7 you do not need a browser switch any more as every modern browser recognizes the XMLHttpRequest object.

i know i dont know as much as you but i am trying my best...
im more familiar with perl and c++.. could you please point out what i have done wrong and please help correct.
i supply people with information on another forum for help with other languages.
could you be a professional and help please

Hint: The first A in Ajax means "asynchronous". I think coming from C++ you should be aware of this construct. Essentially it means that the normal Javascript program flow continues while "some background task" is still running. As soon as the background task triggers some event (in this case the change of the readyState), it will call a so-called "callback function" (onreadystatechange). readyState==4 says: Request complete, status==200 says HTTP OK. In that case you can grab the PHP script output from responseText and do with it whatever you want