Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/09/2015, 09:00
alvaro_trewhela
Invitado
 
Mensajes: n/a
Puntos:
Problema con post ajax

Estimados tengo problema con post en ajax
como estoy aprendiendo estoy haciendo pruebas tengo este codigo:

Código HTML:
Ver original
  1.  
  2.     <script type="text/javascript">
  3.     function createREQ() {
  4.             try {
  5.             req = new XMLHttpRequest(); /* p.e. Firefox */
  6.             }
  7.             catch(err1){
  8.                 try {
  9.                 req = new ActiveXObject('Msxml2.XMLHTTP'); /* algunas versiones IE */
  10.                 }
  11.                 catch (err2) {
  12.                     try {
  13.                     req = new ActiveXObject("Microsoft.XMLHTTP"); /* algunas versiones IE */
  14.                     }
  15.                     catch (err3) {
  16.                     req = false;
  17.                     }
  18.                 }
  19.             }
  20.     return req;
  21.     }
  22.    
  23.     http = new createREQ();
  24.    
  25.     function requestPOST(){
  26.     cat = document.getElementById("cat1").value;
  27.     http.open("POST", "includes/categoria.php", true);
  28.     http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  29.     http.onreadystatechange = changeCat2;
  30.     http.send("?cat1="+cat);
  31.     }
  32.    
  33.     function changeCat2(){
  34.         if(http.readyState == 4){
  35.             if(http.status == 200){
  36.             text = http.responseText;
  37.             alert(text);
  38.             }
  39.         }
  40.     }
  41.    
  42.     </script>
  43.  
  44.  
  45. <title>Page Title</title>
  46. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  47. </head>
  48.  
  49.  
  50. <select id="cat1" onchange="requestPOST();">
  51. <option value="null">Elija</option>
  52. <option value="mujer">Mujer</option>
  53. <option value="hombre">Hombre</option>
  54. <option value="ninos">Niños</option>
  55. <option value="accesorios">Accesorios</option>
  56. <br />
  57.  
  58. <select id="cat2">
  59. <option value="null">Elija</option>
  60.  
  61. </body>
  62. </html>

y el php
Código PHP:
Ver original
  1. <?php
  2.  
  3. $cat = $_POST["cat1"]; echo $cat;
  4.  
  5. ?>

y el alert me duevelve vacio, que puede ser?

Última edición por alvaro_trewhela; 25/09/2015 a las 09:44