<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Comenzando con Ajax</title>
<script type="text/javascript">
function ejecutarAjax(){
var conexion;
if(window.XMLHttpRequest){
conexion = new XMLHttpRequest();
}else{
conexion = new ActiveXObject("Microsoft.XMLHTTP");
}
conexion.onreadystatechange = function(){
if(conexion.readystate == 4 && conexion.status == 200){
document.getElementById("miDiv").innerHTML = conexion.responseText;
}
}
conexion.open("GET", "ejemplo.txt", true);
conexion.send();
}
</script>
</head>
<body>
<div id="miDiv"></div>
<button type="button" onClick="ejecutarAjax()">Ejecutar</button>
</body>
</html>