View Single Post
Old 01-23-2012, 06:59 AM   PM User | #9
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Please try to adhere as close as possible to my first example ... and if it doesn't work, please come back with your rewritten code. Then we will find the problem.

The goal of this forum is not to write the code for you but to guide you to help yourself as good as possible.

Code:
var myvar = "";
var http = XMLHttpRequest();
http.open('GET', 'datatextfile.txt', true);
http.onreadystatechange = function() {
   if(http.readyState == 4 && http.status == 200)
       myvar = http.responseText;
}
http.send(null);
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

Last edited by devnull69; 01-23-2012 at 07:01 AM..
devnull69 is offline   Reply With Quote