[Javascript] Two questions about AJAX

Matt Warden mwarden at gmail.com
Sun Apr 20 14:33:37 CDT 2008


On Sun, Apr 20, 2008 at 2:52 PM, Dave Shaw <dshaw256 at earthlink.net> wrote:
>  First, must I use a new XMLHttpRequest object for each interaction with my
> server, or can one such object be reused for multiple interactions?

You are supposed to use a new object for each interaction. It is
abstracting a "request", after all.

However, from a purely technical possibility perspective, there are
browser differences with whether you can re-use the object or not. See
this thread from May 2005 (FYI the sandbox link referred to in the
thread is now at http://mattwarden.com/sandbox/ajax.htm):

http://lists.evolt.org/archive/Week-of-Mon-20050516/172540.html

>  Second, the first time I tried using AJAX I managed to kick off two
> requests simultaneously, using two XMLHttpRequest objects, two
> onreadystatechange functions, etc. I was using Internet Explorer 7, and this
> worked fine. But when I tried the same page using Firefox, one or the other
> request would complete but the other would fail. I recoded to ensure that
> the requests would be issued serially. But in general, should I be able to
> have multiple asynchronous requests outstanding at the same time, or should
> I ensure that there is only one request pending at a time?

You can definitely have 2 outstanding asynchronous requests at one time.

A July 05 article presents a method for dealing with any number of
outstanding requests at a given time (although the browser typically
restricts the number of outstanding requests to the same host, due to
a suggestion in the http specification). The idea I put forth in this
article is largely irrelevant now, because few people operate with
AJAX directly without a library anymore:

http://www.devx.com/webdev/Article/28695

-- 
Matt Warden
Cincinnati, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the Javascript mailing list