Ver Mensaje Individual
  #14 (permalink)  
Antiguo 26/06/2013, 17:52
Avatar de Franz1628
Franz1628
 
Fecha de Ingreso: marzo-2007
Ubicación: Lima - Perú
Mensajes: 145
Antigüedad: 17 años, 2 meses
Puntos: 26
Respuesta: tengo un problema muy interesante sobre ajax

amigo mejor prueba con esto a ver

Código HTML:
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. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Documento sin t&iacute;tulo</title>
  5. <script type="text/javascript">
  6. function requerir(){
  7.     try{
  8.     req=new XMLHttpRequest();
  9.     }catch(err1){
  10.         try{
  11.         req=new ActiveXObject("Microsoft.XMLHTTP");
  12.         }catch(err2){
  13.             try{
  14.             req=new ActiveXObject("Msxml2.XMLHTTP");
  15.             }catch(err3){
  16.             req= false;
  17.             }
  18.         }
  19.     }
  20. return req;
  21. }
  22. var peticion=requerir();
  23.  
  24. function llamarAjax(){
  25. var aleatorio=parseInt(Math.random()*999999999);
  26. var campo=document.form1.apellido.value;
  27. var campo2=document.form1.nombre.value;
  28. var url="codigo.php?var="+campo+"&r="+aleatorio+"&c2="+campo2;
  29. peticion.open("GET",url,true);
  30. peticion.onreadystatechange =respuestaAjax;
  31. peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  32. peticion.send(null);
  33. }
  34.  
  35. function respuestaAjax(){
  36.     if(peticion.readyState==4)
  37.     {
  38.         if(peticion.status==200)
  39.         {
  40.             var miPeticion  = JSON.parse(peticion.response);
  41.  
  42.            document.getElementById("dina").innerHTML=miPeticion.var;
  43.            document.getElementById("apellidoDiv").innerHTML=miPeticion.c2;
  44.         }
  45.         else
  46.         {
  47.         alert("ha ocurrido un error"+peticion.statusText);
  48.         }
  49.     }
  50.     else
  51.     {
  52.     document.getElementById("dina").innerHTML='<img src="carga.gif" />';
  53.     }
  54. }
  55.  
  56.  
  57. </head>
  58. <div id="dina"></div>
  59. <form action="" method="post" enctype="application/x-www-form-urlencoded" name="form1" id="form1">
  60. <input type="text" name="nombre" id="nombre" />
  61. <div id="dina"></div><!--aqui quiero traer de la pagina solo la variable  $_GET['var']; -->
  62. <input type="text" name="apellido" id="apellido" />
  63. <div id="apellidoDiv"></div> <!--aqui quiero traer de la pagina solo la variable  $_GET['c2'];-->
  64.  
  65. <input name="" type="button" onclick="llamarAjax()" />
  66. </form>
  67. </body>
  68. </html>



codigo.php

Código PHP:
Ver original
  1. <?php
  2.     $array['var'] = $_GET['var'];
  3.     $array['c2'] = $_GET['c2'];
  4.     echo json_encode($array);
  5. ?>
__________________
En mi Blog puedes ver articulos javascript y más...
@Franz1628