473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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..

Jul 23 '05 #1
2 2727
> Where's the "synchronous" part in that? Have I done something wrong?
Sorry, that should be "asynchronous"..

Jul 23 '05 #2
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.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: TJS | last post by:
in a script, a stored procedure is called. I want to verify the procedure is complete before proceeding ahead. How can I have the script wait until a stored procedure is verified as complete...
4
by: Bruno Alexandre | last post by:
Hi guys, I have this page that needs to be populated with 2 diferent web services, and each one takes more or less 10 seconds to finish populate his own part, so I move on to the multi threading...
1
by: nikki.farrah | last post by:
Hi all, this is my first time posting so any help is appreciated! I am doing a simple AJAX request to our server, and I would like the cursor style changed to 'wait' when the user clicks a button...
10
by: shankwheat | last post by:
I'm experimenting with using a AJAX style "processing" icon. The process I'm running in the background with xmlHttp is intensive and takes a 5--10 secs to complete. Instead of my processing icon...
2
by: groups2 | last post by:
I am fixing up a site where the address data for all the addresses for each customer is called with 1 query and then added to a javascript array. The street name of each shipping addresses is...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
7
by: Sebarry | last post by:
Hi, I have a Javascript function that creates an Ajax Request object in order to retrieve data from a database using a PHP script. The Javascript function is invoked by another Javascript function...
1
by: wpt394 | last post by:
I am running a code that works just fine in Firefox, but seems to have trouble in IE. The basic idea is that a travel search process is initiated with one ajax call, and a 2nd ajax call 'updates'...
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.