Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 07:51 PM
1kHz
Guest
 
Posts: n/a
Default 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/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..


  #2  
Old July 23rd, 2005, 07:51 PM
1kHz
Guest
 
Posts: n/a
Default 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"..

  #3  
Old July 23rd, 2005, 07:52 PM
Rich Hephner
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.