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
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