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 simultaneous ajax requests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "simultaneous ajax requests" Watch "simultaneous ajax requests" New topic

simultaneous ajax requests

krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
good day,
i send an ajax request. before i get the response for that request, i make another request. i receive the response of the second, but not the first.
so to solve this problem, i have called the javascript function that contains the second ajax request, from the response of first request. by this way, we could avoid the second request being made, before the first response.

sequence of steps that created problem

1. ajaxrequest1 -------------->server
2. ajaxrequest2 -------------->server
3. ajaxresponse2 <-------------server


my solution

1. ajaxrequest1 -------------->server
2. ajaxresponse1(call javascript function that makes 2nd request) <-------------server
3. ajaxrequest2 -------------->server
4. ajaxresponse2 <-------------server


but this somehow, i think, limits ajax's power. is there any other solution.

have a great day,
krishna prasad g

have a great day,
krishna prasad
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Without seeing your code sounds like you are using global variables to hold the request object. When you make the second request you write over the first.

krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
thankyou eric,
You are right! global variable is the issue.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63839

Libraries such as jQuery and Prototype make it easy to create Ajax requests without the need for global variables.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: simultaneous ajax requests
jQuery in Action, 3rd edition