![]() |
xhr reuse or new?
I was wondering how people are handing their XMLHttpRequest objects. Reusing the object for successive calls or creating a new one? I am currently using both ways. I have an "update" polling system that is using the same XMLHttpRequest for the entire session. Then my app also has user generated commands where it creates a new xhr each time.
So far they both seem to be working fine. I was wondering if anyone has experience that points towards favoring one way over another. Thanks. david_kw |
Saf has a potential memory leak problem with reusing them, IIRC, and iew can get stuck in readystate 2 or 3 indefinitely.
|
I reuse them, but very, very, very carefully, and am not shy in creating a new one if the other one is in use. Reusing does seem to be very buggy at times.
|
I use this little function I wrote, I guess it's creating a new one each time. The only thing I don't like about it is the eval for the call back function, but I can't think of another way to reliably pass values from the initiation of the request to the call back function.
Code:
var x=4;Code:
//******************************************************* |
Quote:
Code:
var x=4; |
Quote:
??? Code:
function getReqObjPost(url,params,func)Code:
<script type="text/javascript"> |
If I understand your goal correctly, you just need to call the function like this.
Code:
if(xmlhttp.status==200)Code:
window.onload=function(){ |
Yep that's the ticket. That mixed with some suggestions from Alien51, I have this. It's better, thanks!
Code:
function getReqObjPost(url,params,func){ |
I will add some more info for you:
If you end up reusing the object, the open method should come before onreadystatechange I talk about it here: http://radio.javaranch.com/pascarell...817890773.html If you are creating an object each time, it really does not matter what order they come in. The standards say it should not matter, IE says otherwise! With the status != 200 you should be using a try catch. I talk about the error that can occur here: http://radio.javaranch.com/pascarell...345471027.html There is another group of fun errors with status codes in th 12XXX. (IE errors) I actually have code in my handlers that see this error and issue a retry attempt. Good thing to do is look at Dojo, Prototype, and YUI on what they do under the covers. You will see notes on errors and other strange things. I have seen almost all of them in my logs at work. I log all clientside errors with a custom framework. Drives me insane with Object Expected and the boss expects you to know what the issue is with a line number! Eric |
Also I love playing with Call() and Apply() with calling functions --Just kills IE5 if you care about that!
Eric |
Quote:
|
Quote:
Eric |
| All times are GMT +1. The time now is 04:29 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.