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

Ayuda en ajax con datos...

Estas en el tema de Ayuda en ajax con datos... en el foro de Frameworks JS en Foros del Web. Tengo un problema con el codigo ajax... al ejecutar el index.php, si me desaparece bien el comobobox con un dato seleccionado y me aparece impreso ...
  #1 (permalink)  
Antiguo 24/02/2011, 22:23
 
Fecha de Ingreso: enero-2010
Mensajes: 47
Antigüedad: 14 años, 3 meses
Puntos: 0
Ayuda en ajax con datos...

Tengo un problema con el codigo ajax... al ejecutar el index.php, si me desaparece bien el comobobox con un dato seleccionado y me aparece impreso en otro div con el dato al darle al boton aceptar, pero lo que tambien quiero siguiendo de eso, es que si quiero cambiar el dato(color) al darle click en el texto cambiar, ahora desaparesca el div con el dato impreso y me devuelva al div del combo para seleccionar otro dato...

estoy atorado en esto... una ayuda por favor...


Codigo ajax:

Código Javascript:
Ver original
  1. function objetoAjax(){
  2.     var xmlhttp=false;
  3.     try {
  4.         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  5.     } catch (e) {
  6.         try {
  7.            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  8.         } catch (E) {
  9.             xmlhttp = false;
  10.         }
  11.     }
  12.  
  13.     if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  14.         xmlhttp = new XMLHttpRequest();
  15.     }
  16.     return xmlhttp;
  17. }
  18.  
  19. function datos(){
  20.     //document.getElementById("combo").style.display == 'none'
  21.     //document.getElementById("boton").style.display == 'none'
  22.    
  23.     document.getElementById("combo").style.display = "none";
  24.     document.getElementById("combo").style.visibility = "hidden";
  25.  
  26.     //donde se mostrará el resultado
  27.     divResultado = document.getElementById('resultado');
  28.     //tomamos el valor de la lista desplegable
  29.     col=document.formulario.s_colonia.value;
  30.    
  31.     //instanciamos el objetoAjax
  32.     ajax=objetoAjax();
  33.     //usamos el medoto POST
  34.     //archivo que realizará la operacion
  35.     ajax.open("POST", "muestra_resultado.php",true);
  36.     ajax.onreadystatechange=function() {
  37.         if (ajax.readyState==4) {
  38.             //mostrar resultados en esta capa
  39.             divResultado.innerHTML = ajax.responseText
  40.         }
  41.     }
  42.    
  43.     ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  44.     //enviando los valores
  45.     ajax.send("colonia="+col)
  46.    
  47. }
  48.  
  49. function cambiar(){
  50.     document.getElementById("resultado").style.display = "block";
  51.     document.getElementById("resultado").style.visibility = "visible";
  52.     document.getElementById("combo").style.display = "block";
  53.     document.getElementById("combo").style.visibility = "visible";
  54. }


Codigo muestra_resultado.php:

Código PHP:
Ver original
  1. <div style="float: left; background: #F93;">
  2.     <?
  3.     include("conexionbd.php");
  4.     //capturar la colonia
  5.     $colonia = $_POST['colonia'];
  6.     echo $colonia;
  7.     ?>
  8. </div>


Codigo index.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>Aparece Div</title>
  6. <script language="JavaScript" type="text/javascript" src="ajax.js"></script>
  7. </head>
  8.  
  9. <body>
  10.  
  11. <form name="formulario" id="formulario" method="POST" action="form.php">
  12.  
  13. <div style="float: left; width:700px; height: 80px;">
  14.     <div id="resultado" style="float: left; width:650px; height: 70px; background: #FC0;">
  15.         <div id="combo" style="float: left; width: 400px; height: 40px;">
  16.             <select name="s_colonia" id="s_colonia" onChange="poner_cp()">
  17.                 <option>Rojo</option>
  18.                 <option>Azul</option>
  19.                 <option>Amarillo</option>
  20.                 <option>Verde</option>
  21.                 <option>Cafe</option>
  22.  
  23.             </select>
  24.            
  25.            
  26.         </div>
  27.         <div id="boton" style="float: left; width: 81px; height: 31px;">
  28.             <img src="btn_aceptar.png" width="81" height="31" style="cursor: pointer" onClick="datos()">
  29.         </div>
  30.     </div>
  31. </div>
  32.  
  33. <div style="float:left; width:100px;">
  34.     <a onclick="cambiar()" style="cursor: pointer;">cambiar</a>
  35. </div>
  36.  
  37. </form>
  38.  
  39. </body>
  40. </html>

Etiquetas: ajax
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 22:32.