1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| function XHRrequest(callback, formatted_command, treatment_file, xhr_Async_mode, num_id, pop, duree_pop_sec, pop_url) {
// Init
var debug = true;
// Envoi des infos à la page de traitement php (methode POST)
var xhr = getXMLHttpRequest();
var sMethod = "POST";
var sUrl = treatment_file;
var bAsync = (xhr_Async_mode === undefined)? true : xhr_Async_mode ;
xhr.onreadystatechange = function() {
if (xhr.readyState < 4) {
document.getElementById("loader").style.display = "inline"; // C'est ça l'appel à ton sablier, tu le fais apparaitre ici et tu le fais disparaitre plus loin si ta requete a abouti
if (pop) {
duree_pop_sec = duree_pop_sec * 1000;
PopUp('http://www.tondomaine.fr/ta_directory_pop_up/'+ pop_url, 'open', 'test', '400', '250', 'left', 'center', duree_pop_sec, false);
}
}
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
document.getElementById("loader").style.display = "none"; // C'est ça l'appel à ton sablier, pour le fermer quand le retour est Ok
if (formatted_command != false) {
callback(xhr.responseText, num_id);
}
}
};
// Envoyer la requete par la methode POST
if (sUrl && formatted_command != false) {
xhr.open( sMethod, sUrl , bAsync );
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(formatted_command);
}
else{
if (debug) alert('no treatment request sent :' + sUrl + ', ' + formatted_command);
}
} |
Partager