| | |
Help about AJAX.
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2006
Posts: 13
Reputation:
Solved Threads: 0
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.
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.
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:
is there any reason you want to access the responseText before it has finished?
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
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?
Plato forgot the nullahedron..
•
•
Join Date: Dec 2006
Posts: 6
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
- AJAX : Am i right with the concept? (JavaScript / DHTML / AJAX)
- New Ajax Tutorial (IT Professionals' Lounge)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: AJAX : Am i right with the concept?
- Next Thread: how to access innerhtml element
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxhelp ajaxjspservlets animate api automatically beta box browser bug calendar captchaformproblem checkbox child class close column cookies createrange() css cursor dependent disablefirebug dom download dropdown editor element engine error events explorer ext file firehose form forms google gwt gxt highlightedword html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump libcurl math matrixcaptcha microsoft mimic object onmouseoutdivproblem onreadystatechange parent pdf php player post problem progressbar rated rating regex runtime scroll search security select session shopping size software sql star stars synchronous text textarea twitter validation w3c web website window windowofwords windowsxp wysiwyg xml \n






