Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XMLHTTPRequest Issues



Mark,

While it's technically reusable, in practical matters, they need to complete or be aborted before reuse can occur & thus it is usually easier to simply create another object so the original can complete in it's own thread independent of the new one. That's why I'd said it wasn't "really" reusable. Also, you may want to use it for disparate purposes within a page & thus reuse requiring an abort might not be desirable. If you are using it for the same update, for instance in a refresh type application, the abort approach could make sense, but since this appeared to be a post operation, I've found the new object approach more beneficial as well as having the benefit of being much simpler to implement.

Niels

On Nov 12, 2006, at 11:09 AM, Mark Baldwin wrote:

Not true! It's totally reusable. The trick is to call open before assigning the readystate handler or doing any other assignments. If you need more info a quick google on 'XMLHttpRequest reuse' will get you what you need.

You will need to look at the readystate and if a request is initiated while one is still outstanding call abort() on the object. Other than that, it is possible to reuse the object as much as you want.

Mark


On Nov 12, 2006, at 7:53 AM, Niels Meersschaert wrote:

XMLHttpRequest isn't really reusable. In this case, what you'd want to do is something like this:

var req;

function buildRequest(url,xml) {
	req  = new XMLHttpRequest()
	req.onreadystatechange = process;
	req.open("POST", url, true);
	req.send(xml);
}

This way, a new XMLHttpRequest object is created, but the reference (req) is maintained outside the function so that your handler can support it. Each time you want to call the request, simply call the buildRequest method with the url & the xml you need.

Niels

On Nov 12, 2006, at 8:55 AM, David Allen wrote:

I have a program that requires multiple XMLHTTPRequests. I use the
following code in a loop:

var req = new XMLHttpRequest();
req.onreadystatechange = process;
req.open("POST", "http://url.com:port/page.cgi";, true);
req.send("Lots and lots of XML")

When I run it the first time, everything goes smoothly, but when I run
it the second time, req.open fails to work - i.e. req.readyState stays
0 afterwards.


Any ideas?

Thanks,

David.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Web-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/web-dev/email@hidden

This email sent to email@hidden


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Web-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/web-dev/email@hidden

This email sent to email@hidden

References: 
 >XMLHTTPRequest Issues (From: "David Allen" <email@hidden>)
 >Re: XMLHTTPRequest Issues (From: Niels Meersschaert <email@hidden>)
 >Re: XMLHTTPRequest Issues (From: Mark Baldwin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.