function a(d, p, s, r, n) {
//d -> json
//p -> object with XHR
//s -> url link for current ajax call
//r -> object with all links for ajax calls
//n -> counter variable to limit ajax calls in case of all 3 servers
// fail to connect
if (n > 3) {
return;
} else {
try {
var x = w(p, s); // function to create cross domain XHR
x.setRequestHeader("Content-Type","application/json;charset=UTF-8", 'X-Requested-With', 'XMLHttpRequest');
x.onreadystatechange = function() {
if (x.readyState != 4) {
return;
}
if(x.status==200){
console.log("success: ", d);
}
if (x.status != 200) {
console.log("t2", d, "N: ", n);
try {
f(d); // throw error with data json
} catch (e) {
a(e.message, p, r.t1, r, n);
}
try {
e(p, s, r); // throw error with error json
} catch (e) {
a(e.message, p, r.err, r, n);
}
}
};
x.send(d);
n++;
} catch (e) {
console.log(e.message);
}
}
};
I try to make two async ajax calls inside ajax call to my own servers, in case of outer ajax call did not succeed. I get result, that only last ajax call is really goes out of browser to the server. I can't use callback, as I only need this two ajax calls in case first one fail.
The main trick - I can't use jQuery, and this ajax should be cross-browser compatible -> IE8,9. I already test it on my servers, and it work with cross domain. the only thing is breaking my mind, how to make this code to run 2 ajax calls on fail of first one. I do not need COMET( subscribe) or WebSockets.
Please help me somebody.
Aucun commentaire:
Enregistrer un commentaire