Connecting Tech Pros Worldwide Forums | Help | Site Map

AJAX: Have to wait for it to complete before proceeding?

1kHz
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi all..

I'm new with this Ajax thingy and have done some experimenting. I did
some codes according to examples from
http://www.webpasties.com/xmlHttpRequest/
and
http://www.jamesdam.com/ajax_login/login.html

In my code, I request a PHP page that will iterate 10000 times and
return a 10000 line of text, and then put it in a DIV. I initiate the
Ajax from a button click. What I notice is, if I click some other
hyperlink in the page after clicking the button, it will wait until all
the Ajax processes are done before going to the link. Is this the norm?
Where's the "synchronous" part in that? Have I done something wrong?

These are some snippets from my code:
-------------------------------------------------
var req = new XMLHttpRequest();

function GetContent()
{
req.open("GET", "test2.php", true);
req.onreadystatechange = ReadyStateChange;
req.send(null);
}

function ReadyStateChange()
{
var panel = document.getElementById('theDiv');
if (req.readyState == 4)
{
panel.innerHTML = req.responseText;
}
}
-------------------------------------------------

Thanks..


1kHz
Guest
 
Posts: n/a
#2: Jul 23 '05

re: AJAX: Have to wait for it to complete before proceeding?


> Where's the "synchronous" part in that? Have I done something wrong?
Sorry, that should be "asynchronous"..

Rich Hephner
Guest
 
Posts: n/a
#3: Jul 23 '05

re: AJAX: Have to wait for it to complete before proceeding?


Hi all..


I'm new with this Ajax thingy and have done some experimenting. I did
some codes according to examples from
http://www.webpasties.com/xmlH*ttpRequest/and
http://www.jamesdam.com/ajax_l*ogin/login.html


In my code, I request a PHP page that will iterate 10000 times and
return a 10000 line of text, and then put it in a DIV. I initiate the
Ajax from a button click. What I notice is, if I click some other
hyperlink in the page after clicking the button, it will wait until all

the Ajax processes are done before going to the link. Is this the norm?

Where's the "synchronous" part in that? Have I done something wrong?


These are some snippets from my code:
------------------------------*-------------------
var req = new XMLHttpRequest();


function GetContent()
{
req.open("GET", "test2.php", true);
req.onreadystatechange = ReadyStateChange;
req.send(null);
}


function ReadyStateChange()
{
var panel = document.getElementById('theDi*v');
if (req.readyState == 4)
{
panel.innerHTML = req.responseText;
}
}
------------------------------*-------------------


Thanks..


I'm new at this too, but that last argument in req.open is where you
specify synchronous or asynchronous. I'm betting if you change:

req.open("GET", "test2.php", true);

to

req.open("GET", "test2.php", false);

You'll get what you need.

Closed Thread


Similar JavaScript / Ajax / DHTML bytes