Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/03/2011, 01:57
vBArgentina
 
Fecha de Ingreso: octubre-2010
Ubicación: Mountain View, United States.
Mensajes: 87
Antigüedad: 13 años, 6 meses
Puntos: 1
Exclamación Envio de Formulario POST con Ajax

Hola chicos, tengo un problema con Ajax.

Bueno la cosa es asi, el ajax funciona bien, pero a la hora
de tomar las variables de POST no las toma.

Envio el formulario con method="post" pero cuando quiero recibir
las variables enviadas por el formulario
no las toma.

Encontre algo que me podria ayudar, pero siempre lo envia en GET y yo no quiero eso.


Les dejo los codigos:


Ajax.js:
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 MostrarConsulta(datos){
  20.         divResultado = document.getElementById('resultado');
  21.         ajax=objetoAjax();
  22.         ajax.open("POST", datos);
  23.         ajax.onreadystatechange=function() {
  24.                 if (ajax.readyState==4) {
  25.                         divResultado.innerHTML = ajax.responseText
  26.                 }
  27.         }
  28.         ajax.send(null)
  29. }


El formulario:

Código PHP:
Ver original
  1. <form method="post" onsubmit="MostrarConsulta('consulta.php'); return false" ><br />
  2. <input type="hidden" name="inpro" id="inpro" value="<?php echo "$idp"; ?>"/>
  3. <input type="hidden" name="fromuser" id="fromuser" value="<?php echo $_SESSION['username']; ?>"/>
  4. <input type="hidden" name="date" id="date" value="<?php echo "$date"; ?>"/>
  5. <textarea name="text" id="text" rows="5" tabindex="1" cols="50" style="margin-left:30px;"></textarea><br><br><br>
  6.   <div id="resultado"></div>
  7. <input value="Agregar" onclick="document.formulario.submit()" class="input_submit" type="submit" name="posting"/><br /><br />
  8. </form>


el archivo Consulta.php
Código PHP:
Ver original
  1. <?php
  2. $inpro = stripslashes($_POST['inpro']);
  3. $date = stripslashes($_POST['date']);
  4. $text = stripslashes($_POST['text']);                
  5. $fromuser = stripslashes($_POST['fromuser']);
  6. $date = stripslashes($_POST['date']);
  7.  
  8. if (empty($text)) {
  9.     echo "<br><b>Ingresa un texto!<br /></b>";  $Error=1;
  10. }
  11.  
  12. if ($Error!=1){
  13. $link = mysql_connect("localhost", "root", "idontknow");
  14. mysql_select_db("thefantasticdb",$link);
  15. $msquery3 = mysql_query("INSERT INTO comments (`inpro`, `fromuser`, `date`, `text`) VALUES
  16. ('$inpro', '$fromuser', '$date', '$text')");
  17. echo "exito!";
  18. }
  19.  
  20. ?>

A la hora de tomar " $text = stripslashes($_POST['text']); " no lo toma.


Espero puedan ayudarme amigos.