Solució exercici1-Ajax
De wikiserver
La revisió el 18:43, 20 març 2014 per Asalinas (Discussió | contribucions) (Es crea la pàgina amb «Fitxer Javascript: <pre> var xhr; function inici(){ if (window.ActiveXObject) { //Iexplorer xhr = new ActiveXObject("Microsoft.XMLHTTP"); } else …».)
Fitxer Javascript:
var xhr;
function inici(){
if (window.ActiveXObject) { //Iexplorer
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) { //Tots els altres navegadors que soporten ajax
xhr = new XMLHttpRequest();
}
else {
throw new Error("Ajax is not supported by this browser");
}
xhr.open('GET', 'info.php');
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status >= 200 && this.status < 300) {
document.getElementById('content').innerHTML = this.responseText;
}
}
}
xhr.send(null);
}
window.onload = inici;
Fitxer HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="exercici1.js"></script>
</head>
<body>
<div id="content">TODO write content</div>
</body>
</html>
Fitxer PHP:
<?php echo phpinfo(); ?>