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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <html>
<head>
<SCRIPT language="JavaScript"><!--
var xhr_object = null;
var response = null;
function getXhr(){
if(window.XMLHttpRequest) // Firefox et autres
xhr_object = new XMLHttpRequest();
else if(window.ActiveXObject){ // Internet Explorer
try {
xhr_object = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else { // XMLHttpRequest non supporté par le navigateur
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
xhr_object = false;
}
}
function mydesstudy(study){
getXhr();
// On défini ce qu'on va faire quand on aura la réponse
xhr_object.onreadystatechange = function(){
// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
if(xhr_object.readyState == 4 /*&& xhr_object.status == 200*/){
alert(xhr_object.responseText);
document.getElementById("info").innerHTML=xhr_object.responseText;
}
}
// definition of the data passed to the phpscript
var data=study;
var filename = "../script.aspx"; //to be done
var method = 'GET';
if(method == "GET" && data != null) {
v = "data="+data;
filename += "?"+v;
data = null;
}
xhr_object.open(method, filename, true);
if(method == "POST") xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr_object.send(data);
}
//--> </SCRIPT>
</head>
<body>
<fieldset>
<legend>Cadre</legend>Test d'une requête XMLHttpRequest
<br />
<FORM ACTION="../perlscript/new-sas.pl" METHOD="POST" NAME="INI">
<select onclick="mydesstudy(this.form.study.value)" onchange="mydesstudy(this.form.study.value)" size="1" name="study">
<option value="Hello" selected="selected">Hello</option>
<option value="World">World</option>
</select>
</FORM>
</fieldset>
<div id="info">Here</div>
</body>
</html> |
Partager