Ver Mensaje Individual
  #4 (permalink)  
Antiguo 04/12/2009, 11:49
Avatar de jackson666
jackson666
 
Fecha de Ingreso: noviembre-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 1.971
Antigüedad: 14 años, 6 meses
Puntos: 65
Respuesta: No me carga el contenido data.txt en html

O no tenes corriendo el apache, o no estas poniendo en la url localhost/turuta/tuarchivo.php
Por las dudas te dejo mi coddigo que si funciona
Código PHP:
<html>
<
head>
<
title>Funcion AJAX</title>
</
head>
<
body>
<
script type="text/javascript">
var 
xhr;
function 
startAjax(){
    if(
window.ActiveXObject){
        
xhr=new ActiveXObject("Microsoft.XMLHTTP");
    }else if(
window.XMLHttpRequest){
        
xhr=new XMLHttpRequest();
    }
xhr.open("GET","data.txt");
xhr.onreadystatechange=callback;
xhr.send(null);
}
function 
callback(){
    if(
xhr.readyState==4){
        if(
xhr.status==200){
        var 
resp=xhr.responseText;
        var 
div=document.getElementById("targetDiv");
        
div.innerHTML=resp;
        }
    }
}
</script>

<input type="button" value="Fetch the Message" onclick="startAjax();" />
<br /><br />
<div id="targetDiv">
hola
</div>
</body>
</html> 
Solo deberias crear un txt llamado "data"

Última edición por jackson666; 04/12/2009 a las 12:18