PDA

View Full Version : Can I fire off 2 ajax instances?


rfresh
05-02-2009, 07:45 AM
I am launching the first ajax instance and doing some file processing on my server. While waiting for this I have a stop link that I want to click on to stop this first ajax process (if I get tired of waiting for example).

The stop link fires off a separate ajax instance that, on the server side, simply sets a global php flag to abort. The first ajax procedure constantly checks this flag.

Can I create two ajax http instances? In my code below, I create http and httpStop.

It doesn't seem to be working so I'm wondering if what I'm doing is possible?


function createRequestObject() {
if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
var xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType)
xmlhttp.overrideMimeType('text/xml');
}
else if (window.ActiveXObject) { // IE
try {
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!xmlhttp) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
return xmlhttp;
}
var http = createRequestObject();
var httpStop = createRequestObject();


The ajax code is pretty straight forward for both of these ajax functions so I'm not listing them here - my question is more of a structural ajax question: can I fire off two ajax functions if they each have their own createRequestObject?

Thanks

oesxyl
05-02-2009, 05:04 PM
the second instance will be created after http.abort() in the click event or what ever you use in that link so I don't see a problem here.

best regards

rfresh
05-02-2009, 06:07 PM
I'm not using http.abort() - when I click on the 2nd ajax link it just calls a php script on the server and it sets a global php var. The 1st Ajax instance is still processing files and will ck this bar in it's loop. So I can't use http.abort(). I need 2 Ajax instances running for a brief time period at least, at the same time. Can this be done? That's why I used httpStop to create the 2nd instance.

oesxyl
05-02-2009, 06:43 PM
I'm not using http.abort() - when I click on the 2nd ajax link it just calls a php script on the server and it sets a global php var. The 1st Ajax instance is still processing files and will ck this bar in it's loop. So I can't use http.abort(). I need 2 Ajax instances running for a brief time period at least, at the same time. Can this be done? That's why I used httpStop to create the 2nd instance.
try this:

https://blueprints.dev.java.net/ajax-faq.html#concurrent_requests

best regards