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 38 39 40
| function ajax(data, nom_hidden, id_form){
var xhr_object = null;
if(window.XMLHttpRequest) // Firefox
xhr_object = new XMLHttpRequest();
else if(window.ActiveXObject) // Internet Explorer
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
else { // XMLHttpRequest non supporte par le navigateur
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
return;
}
xhr_object.open("POST", document.getElementById(id_form).action + "?hidden="+ nom_hidden, true);
xhr_object.onreadystatechange = function() {
if(xhr_object.readyState == 4){
// check that we received a successful response from the server
if(xhr_object.status == 200 ){
xhr_object.responseText ;
eval(xhr_object.responseText);
}else {
// an http problem has occured
//xhr_object.readyState :4
// xhr_object.status :12029 / 12031
// xhr_object.statusText : Unknown
display_err(xhr_object.statusText);
}
}else{alert("not ready");
}
}
xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// alert("Envois des données !!");
xhr_object.send(data);
} |
Partager