Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Leer desde ajax un .php

Estas en el tema de Leer desde ajax un .php en el foro de Frameworks JS en Foros del Web. Hola Estoy haciendo un ejemplo q tengo en un ebook("Ajax for dummies")...el cual se supone que trae lo q contiene un archivo php..el asunto es ...
  #1 (permalink)  
Antiguo 11/04/2006, 00:42
Avatar de B**
B**
 
Fecha de Ingreso: enero-2006
Ubicación: Monterrey,Mexico
Mensajes: 952
Antigüedad: 18 años, 3 meses
Puntos: 3
Leer desde ajax un .php

Hola
Estoy haciendo un ejemplo q tengo en un ebook("Ajax for dummies")...el cual se supone que trae lo q contiene un archivo php..el asunto es que no me hace lo q ellos dicen q hace... no me marca errores el editor... pero no hace nada, el codigo es el siguiente:
Código PHP:

<html>
<
head>
       <
script languaje="javascript">
            var 
Ajaxfalse;
            if(
window.XMLHttpRequest){
              
Ajax= new XMLHttpRequest();
            }
            else if(
window.ActiveXObject){
                
Ajax= new ActiveXObject("Microsoft.XMLHTTP");
            }

            function 
getData(datasource,divID){
              if(
Ajax){
                var 
obj=document.getElementById(divID);
                
Ajax.open("GET",datasource);
                
Ajax.onreadystatechange=function(){
                  if(
Ajax.readystate == && Ajax.status == 200){
                    
obj.innerHTML=Ajax.responsetext;

                  }
                }
            
Ajax.send(null);

              }

            }
    
</script>
</head>
<body>
            <form>
                <input type =submit value = "enseña msg" onclick ="getData('data.php','targetDiv')">
            </form>
            
    <div id="targetDiv">

    </div>

</body>
</html> 
Y lo que tengo en data.php es:
Código PHP:
<?php
    
echo 'Este texto viajo por ajax';
 
?>
Ahhh y los 2 archivos los tengo en el mismo directorio, y lo corro desde el localhost preview de PHP design..


Haber si alguien me puede ayudar...gracias de antemano
  #2 (permalink)  
Antiguo 11/04/2006, 01:18
Avatar de Mickel  
Fecha de Ingreso: mayo-2002
Ubicación: Lima, Peru
Mensajes: 4.619
Antigüedad: 21 años, 11 meses
Puntos: 7
Prueba esto:

function nuevoAjax() {
var xmlhttp=false;
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp=false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp=new XMLHttpRequest();
}
return xmlhttp;
}

function getData(datasource,divID) {
contenedor=document.getElementById(divID);
ajax=nuevoAjax();
ajax.open("GET",datasource,true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
contenedor.innerHTML=ajax.responseText;
}
}
ajax.send(null);
}
__________________
No tengo firma ahora... :(
  #3 (permalink)  
Antiguo 11/04/2006, 16:23
Avatar de B**
B**
 
Fecha de Ingreso: enero-2006
Ubicación: Monterrey,Mexico
Mensajes: 952
Antigüedad: 18 años, 3 meses
Puntos: 3
Pues lo hace en explorer, pero el problema es q le doy click al boton y sale el mensaje k tenia en el php pero se desaparece solito y bien rapido.. y pues en el firefox no funciona..el codigo final q tengo es este:
Código PHP:

<html>
<
head>
       <
script languaje="javascript">

            function 
nuevoAjax() {
                    var 
xmlhttp=false;
                    try {
                    
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (
e) {
                    try {
                    
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                         } catch (
E) {
                            
xmlhttp=false;
                    }
                    }
                    if (!
xmlhttp && typeof XMLHttpRequest!='undefined') {
                        
xmlhttp=new XMLHttpRequest();
                    }
                    return 
xmlhttp;
                }

           function 
getData(datasource,divID) {
                    
contenedor=document.getElementById(divID);
                    
ajax=nuevoAjax();
                    
ajax.open('GET',datasource,false);
                    
ajax.onreadystatechange=function() {
                    if (
ajax.readyState==4) {
                        
contenedor.innerHTML=ajax.responseText;
                    }
                    }
                
ajax.send(null);
                }
    
</script>
</head>
<body>
            <form>
                <input type =submit value = "enseña msg" onclick ="getData('data.php','targetDiv')">
            </form>

    <div id="targetDiv">

    </div>

</body>
</html> 
Alguna sugerencia?
  #4 (permalink)  
Antiguo 12/04/2006, 17:44
Avatar de B**
B**
 
Fecha de Ingreso: enero-2006
Ubicación: Monterrey,Mexico
Mensajes: 952
Antigüedad: 18 años, 3 meses
Puntos: 3
Por si alguien le interesa el problema lo solucione poniendo el form dentro del div... y entonces asi ya no se me aparece y desaparece lo k tenia en el archivo php..
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:23.