<html>
<head>
<script>
function getXhr()
{
if(window.XMLHttpRequest) xhr = new XMLHttpRequest();
else if(window.ActiveXObject)
{
try
{
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else
{
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour");
xhr = false;
}
}
function submitform()
{
document.getElementById("ajax_data").innerHTML = "";
var xhr = getXhr();
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200)
{
document.getElementById("ajax_data").innerHTML = xhr.responseText;
}
}
};
xhr.open("GET", "hello.txt", true);
xhr.send(null);
}
</script>
<style type="text/css">
#ajax_data {
border:1px solid red;
height:32px;
width:100px;
}
</style>
</head>
<body>
<form method="post" name="ajax" action="">
<input type="button" value="Envoyer" onclick="submitform()">
</form>
<div id="ajax_data"></div>
</body>
</html>