User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 373,507 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,928 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1052 | Replies: 2
Reply
Join Date: Oct 2006
Location: Jordan
Posts: 13
Reputation: khusani is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
khusani khusani is offline Offline
Newbie Poster

Help Help about AJAX.

  #1  
Dec 20th, 2006
I am developing a page with many of AJAX methods.

what i want to do is, inside a javascript function, there is a loop. inside this loop i want to call the AJAX methods and retrieve the response text.

when i do that i recieve an exception telling me that the data is not available yet. because the readyState is 1 (loading) not 4 (finish).

how can i access the response text while the readyState is 1?

thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 916
Reputation: MattEvans will become famous soon enough MattEvans will become famous soon enough 
Rep Power: 5
Solved Threads: 46
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Help about AJAX.

  #2  
Dec 20th, 2006
you shouldn't access the response text until it is 'there',

what you should do is either wait for the request to reach the ready state 4 (best achieved by using an event listener), or set the request to syncronous, by setting the last argument in an 'open' method to false:

xmlHttp.open("GET", url, true);
<any code here will be executed as soon as the open method has been called 
xmlHttp.open("GET", url, false);
<any code here will be executed when the request is finished.

is there any reason you want to access the responseText before it has finished?
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Dec 2006
Posts: 6
Reputation: nemo5 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nemo5 nemo5 is offline Offline
Newbie Poster

Solution Re: Help about AJAX.

  #3  
Dec 31st, 2006
Your problem is, that the subsequent calls to the ajaxrequest are using the same global variable for the request. The posted answer is right in the point to make the calls synchronous. Other thing you can do is to use namespacing and nested functions to create new httprequest object for each ajax call.

Other thing is, you can read data partially send, but that is ready state 3 and is considered unsafe (but can be done, you just have to make sure you know what you've read and what not when the readystate changes to 4 and the rest of the data arrives). Readystate 1 means you just sent the request, but no response is back yet.
For a man without a destination no wind is favourable

http://www.vydavatelstvo-f.sk
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:12 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC