-
-
Save anonymous/23d0c4e877bfc1c84be2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getXHR() { | |
var xhr = null; | |
if (window.XMLHttpRequest || window.ActiveXObject) { | |
if (window.ActiveXObject) { | |
try { | |
xhr = new ActiveXObject("Msxml2.XMLHTTP"); | |
} catch(e) { | |
xhr = new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
} else { | |
xhr = new XMLHttpRequest(); | |
} | |
} else { | |
alert("Impossible d'utiliser XMLHttpRequest sur votre navigateur."); | |
return null; | |
} | |
return xhr; | |
} | |
function update() { | |
var liste = document.forms[0].elements['liste']; | |
var caseA = document.forms[0].elements['A']; | |
var caseB = document.forms[0].elements['V']; | |
var caseC = document.forms[0].elements['C']; | |
/* Requête AJAX */ | |
xhr.onreadystatechange = function() { | |
if(xhr.readyState == 4 && (xhr.status == 0 || xhr.status = 200)) { | |
/* Affichage dans l'input */ | |
var finalInput = document.forms[0].elements['final']; | |
var chaine = ""; | |
chaine += liste.value; | |
if(caseA.checked) { | |
chaine += " A"; | |
} | |
if(caseB.checked) { | |
chaine += " B"; | |
} | |
if(caseC.checked) { | |
chaine += " C"; | |
} | |
finalInput.value = chaine; | |
} | |
}; | |
xhr.open('POST','/script.php', true); | |
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | |
xhr.send('listeValue='+liste.value+'&case_a='+caseA.checked+'&case_b='+caseB.checked+'&case_c='+caseC.checked); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment