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 74 75 76 77 78 79 80 81 82
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>testAjax</title>
<script type='text/javascript'>
function getXMLHTTP(){
var xhr=null;
if(window.XMLHttpRequest) // Firefox et autres
xhr = new XMLHttpRequest();
else if(window.ActiveXObject){ // Internet Explorer
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e1) {
xhr = null;
}
}
}
else { // XMLHttpRequest non supporté par le navigateur
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
}
return xhr;
}
function callUpadeScripts() {
var _xmlHttp = getXMLHTTP();
_xmlHttp.open("GET","requete.php");
_xmlHttp.onreadystatechange=function() {
if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
document.getElementById('contenu').innerHTML=_xmlHttp.responseText;
evalueScripts('contenu');
}
};
// envoi de la requête
_xmlHttp.send(null)
}
function callUpadeNoScripts() {
var _xmlHttp = getXMLHTTP();
_xmlHttp.open("GET","requete.php");
_xmlHttp.onreadystatechange=function() {
if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
document.getElementById('contenu').innerHTML=_xmlHttp.responseText;
}
};
// envoi de la requête
_xmlHttp.send(null)
}
function evalueScripts(targetId) {
var mesScripts = document.getElementById(targetId).getElementsByTagName("script");
for (var i=0; i<mesScripts.length; i++) {
window.eval(mesScripts[i].innerHTML);
}
}
</script>
</head>
<body>
<div id="bouton">
Div Déclencheur
<br />
<label>
<input type="button" name="appel" value="Appel Sans Interpretation JS" id="appel" onclick="callUpadeNoScripts();"/>
</label>
<br />
<label>
<input type="button" name="appel2" value="Appel Avec Interpretation JS" id="appel" onclick="callUpadeScripts();"/>
</label>
</div>
<br />
<div id="contenu">Div Récepteur</div>
</body>
</html> |
Partager