Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > AJAX: Have to wait for it to complete before proceeding?

Reply
Thread Tools

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

 
 
1kHz
Guest
Posts: n/a
 
      05-17-2005
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..

 
Reply With Quote
 
 
 
 
1kHz
Guest
Posts: n/a
 
      05-17-2005
> Where's the "synchronous" part in that? Have I done something wrong?
Sorry, that should be "asynchronous"..

 
Reply With Quote
 
 
 
 
Rich Hephner
Guest
Posts: n/a
 
      05-17-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi-threading: wait for tasks to complete markspace Java 4 12-15-2009 05:11 PM
POpen - Wait For Process To Complete McGirr, Mark A ILMB:EX Python 0 12-20-2007 04:22 PM
How to make "fork/wait" to WAIT longer? Huey C Programming 1 03-01-2004 02:01 PM
wait until stored procedure is complete TJS ASP .Net 2 02-11-2004 02:22 PM
Execute a stored procedure from ASP page, but don't wait for it to complete? Richard Morey ASP General 3 01-22-2004 01:14 AM



Advertisments