Ver Mensaje Individual
  #4 (permalink)  
Antiguo 26/06/2013, 14:48
Avatar de jor_0203
jor_0203
 
Fecha de Ingreso: octubre-2011
Ubicación: mexico
Mensajes: 760
Antigüedad: 12 años, 6 meses
Puntos: 8
Respuesta: tengo un problema muy interesante sobre ajax

lo puse asi y no me sale , la pagina es a1,php
Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Documento sin t&iacute;tulo</title>
  6. <script type="text/javascript">
  7. function requerir(){
  8.     try{
  9.     req=new XMLHttpRequest();
  10.     }catch(err1){
  11.         try{
  12.         req=new ActiveXObject("Microsoft.XMLHTTP");
  13.         }catch(err2){
  14.             try{
  15.             req=new ActiveXObject("Msxml2.XMLHTTP");
  16.             }catch(err3){
  17.             req= false;
  18.             }
  19.         }
  20.     }
  21. return req;
  22. }
  23. var peticion=requerir();
  24.  
  25. function llamarAjax(){
  26. var aleatorio=parseInt(Math.random()*999999999);
  27. var campo=document.form1.apellido.value;
  28. var campo2=document.form1.nombre.value;
  29. var url="codigo.xml?var="+campo+"&r="+aleatorio+"&c2="+campo2;
  30. peticion.open("GET",url,true);
  31. peticion.onreadystatechange =respuestaAjax;
  32. peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  33. peticion.send(null);
  34. }
  35.  
  36. function respuestaAjax(){
  37.     if(peticion.readyState==4)
  38.     {
  39.         if(peticion.status==200)
  40.         {
  41.         //alert(peticion.responseText);
  42.        
  43.      
  44.         var dina =  peticion.responseXML.getElementsByTagName("var")[0];
  45.         var apellidoDiv=  peticion.responseXML.getElementsByTagName("c2")[0];
  46.  
  47.            document.getElementById("dina").innerHTML=dina.childNodes[0].nodeValue;
  48.            document.getElementById("apellidoDiv").innerHTML=apellidoDiv.childNodes[0].nodeValue;
  49.         }
  50.         else
  51.         {
  52.         alert("ha ocurrido un error"+peticion.statusText);
  53.         }
  54.     }
  55.     else
  56.     {
  57.     document.getElementById("dina").innerHTML='<img src="carga.gif" />';
  58.     }
  59. }
  60.  
  61.  
  62. </script>
  63. </head>
  64. <body>
  65. <div id="dina"></div>
  66. <form action="" method="post" enctype="application/x-www-form-urlencoded" name="form1" id="form1">
  67. <label>
  68. <input type="text" name="nombre" id="nombre" />
  69. <div id="dina"></div><!--aqui quiero traer de la pagina solo la variable  $_GET['var']; -->
  70. </label>
  71. <label>
  72. <input type="text" name="apellido" id="apellido" />
  73. <div id="apellidoDiv"></div> <!--aqui quiero traer de la pagina solo la variable  $_GET['c2'];-->
  74. </label>
  75.  
  76. <input name="" type="button" onclick="llamarAjax()" />
  77. </form>
  78. </body>
  79. </html>

la pagina es codigo.xml no se si asi esta bien
gracias

Código XML:
Ver original
  1. <?php
  2.  
  3.   header('Content-Type: text/xml');
  4.    echo "<?xml version=\"1.0\"?><var>".$_GET['var']."</var><c2>".$_GET['c2']."</c2>";
  5.    
  6. ?>