File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes AJAX lag issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "AJAX lag issue" Watch "AJAX lag issue" New topic

AJAX lag issue

Bill Clar
Ranch Hand

Joined: Sep 21, 2006
Posts: 163

I have the most peculiar AJAX/Javascript problem. I'm having difficulty retrieving the value returned from an AJAX request.

I'm assigning the XMLHttpRequest.responseText value to a simple text field. When I try to retrieve this very field, the info
is undefined. I can see it populated on the screen in the text field, but I cannot retrieve it.

If I call an alert() on the field, it's undefined. If I call alert() a second time, the value appears.

Does AJAX have some sort of lag that prevents or hinders the user from retrieving the XMLHttpRequest.responseText data? Do I need to do something more
than ensure the state and status of the AJAX object are successful?


Bill Clar

Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
You are making an asynchronous request, not a synchronous one.

You make the Ajax call and it continues on its way, it does not wait til it comes back.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62746

In other words, you can't check the value before it gets set and expect it to be there

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: AJAX lag issue