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

Como enviar mas valores al GET ya que solo acepta un solo valor

Estas en el tema de Como enviar mas valores al GET ya que solo acepta un solo valor en el foro de Frameworks JS en Foros del Web. Como enviar mas valores al GET ya que solo acepta un solo valor, ya que no me esta llegando el parametro de la fecha. @import ...
  #1 (permalink)  
Antiguo 03/05/2010, 16:05
 
Fecha de Ingreso: marzo-2010
Mensajes: 432
Antigüedad: 14 años, 1 mes
Puntos: 11
Como enviar mas valores al GET ya que solo acepta un solo valor

Como enviar mas valores al GET ya que solo acepta un solo valor, ya que no me esta llegando el parametro de la fecha.

Código HTML:
Ver original
  1. <input type='hidden' name='fecha' value='2010-05-01 12:55:01'>

index.html

Código HTML:
Ver original
  1. <script type="text/javascript">
  2. function showUser(str, fecha)
  3. {
  4. if (str=="")
  5.   {
  6.   document.getElementById("txtHint").innerHTML="";
  7.   return;
  8.   }
  9. if (window.XMLHttpRequest)
  10.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  11.   xmlhttp=new XMLHttpRequest();
  12.   }
  13. else
  14.   {// code for IE6, IE5
  15.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  16.   }
  17. xmlhttp.onreadystatechange=function()
  18.   {
  19.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  20.    {
  21.    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  22.     }
  23.   }
  24. xmlhttp.open("GET","getuser.php?q="+str&fecha="+fecha, true);
  25. xmlhttp.send();
  26. }
  27. </head>
  28.  
  29. <input type='hidden' name='fecha' value='2010-05-01 12:55:01'>
  30.  
  31. <select name="users" onchange="showUser(this.value)">
  32. <option value="">Select a person:</option>
  33. <option value="1">Peter Griffin</option>
  34. <option value="2">Lois Griffin</option>
  35. <option value="3">Glenn Quagmire</option>
  36. <option value="4">Joseph Swanson</option>
  37. </form>
  38. <br />
  39. <div id="txtHint"><b>Person info will be listed here.</b></div>
  40.  
  41. </body>
  42. </html>

getuser.php

Código PHP:
Ver original
  1. <?php
  2. $q=$_GET["q"];
  3. $fecha=$_GET["fecha"];
  4.  
  5. $con = mysql_connect('localhost', 'peter', 'abc123');
  6. if (!$con)
  7.   {
  8.   die('Could not connect: ' . mysql_error());
  9.   }
  10.  
  11. mysql_select_db("ajax_demo", $con);
  12.  
  13. $sql="SELECT * FROM user WHERE id = '".$q."' and fecha = '".$fecha."'  ";
  14.  
  15. $result = mysql_query($sql);
  16.  
  17. echo "<table border='1'>
  18. <tr>
  19. <th>Firstname</th>
  20. <th>Lastname</th>
  21. <th>Age</th>
  22. <th>Hometown</th>
  23. <th>Job</th>
  24. </tr>";
  25.  
  26. while($row = mysql_fetch_array($result))
  27.   {
  28.   echo "<tr>";
  29.   echo "<td>" . $row['FirstName'] . "</td>";
  30.   echo "<td>" . $row['LastName'] . "</td>";
  31.   echo "<td>" . $row['Age'] . "</td>";
  32.   echo "<td>" . $row['Hometown'] . "</td>";
  33.   echo "<td>" . $row['Job'] . "</td>";
  34.   echo "</tr>";
  35.   }
  36. echo "</table>";
  37.  
  38. ?>
  #2 (permalink)  
Antiguo 04/05/2010, 01:35
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
Respuesta: Como enviar mas valores al GET ya que solo acepta un solo valor

Hola:

Has probado escapando el primer parámetro.

xmlhttp.open("GET","getuser.php?q="+escape(str) + "&fecha="+fecha, true);

... y veo que no estás concadenando bien los parámetros...

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #3 (permalink)  
Antiguo 04/05/2010, 08:33
 
Fecha de Ingreso: marzo-2010
Mensajes: 432
Antigüedad: 14 años, 1 mes
Puntos: 11
Respuesta: Como enviar mas valores al GET ya que solo acepta un solo valor

Gracias pero me dice que es la variable de fecha que es "undefined", porque pasa eso ?

Saludos
  #4 (permalink)  
Antiguo 04/05/2010, 08:43
 
Fecha de Ingreso: julio-2009
Mensajes: 29
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: Como enviar mas valores al GET ya que solo acepta un solo valor

Cita:
Iniciado por tazzwt Ver Mensaje
Como enviar mas valores al GET ya que solo acepta un solo valor, ya que no me esta llegando el parametro de la fecha.

Código HTML:
Ver original
  1. <input type='hidden' name='fecha' value='2010-05-01 12:55:01'>

index.html

Código HTML:
Ver original
  1. <script type="text/javascript">
  2. function showUser(str, fecha)
  3. {
  4. if (str=="")
  5.   {
  6.   document.getElementById("txtHint").innerHTML="";
  7.   return;
  8.   }
  9. if (window.XMLHttpRequest)
  10.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  11.   xmlhttp=new XMLHttpRequest();
  12.   }
  13. else
  14.   {// code for IE6, IE5
  15.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  16.   }
  17. xmlhttp.onreadystatechange=function()
  18.   {
  19.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  20.    {
  21.    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  22.     }
  23.   }
  24. xmlhttp.open("GET","getuser.php?q="+str&fecha="+fecha, true);
  25. xmlhttp.send();
  26. }
  27. </head>
  28.  
  29. <input type='hidden' name='fecha' value='2010-05-01 12:55:01'>
  30.  
  31. <select name="users" onchange="showUser(this.value)">
  32. <option value="">Select a person:</option>
  33. <option value="1">Peter Griffin</option>
  34. <option value="2">Lois Griffin</option>
  35. <option value="3">Glenn Quagmire</option>
  36. <option value="4">Joseph Swanson</option>
  37. </form>
  38. <br />
  39. <div id="txtHint"><b>Person info will be listed here.</b></div>
  40.  
  41. </body>
  42. </html>

getuser.php

Código PHP:
Ver original
  1. <?php
  2. $q=$_GET["q"];
  3. $fecha=$_GET["fecha"];
  4.  
  5. $con = mysql_connect('localhost', 'peter', 'abc123');
  6. if (!$con)
  7.   {
  8.   die('Could not connect: ' . mysql_error());
  9.   }
  10.  
  11. mysql_select_db("ajax_demo", $con);
  12.  
  13. $sql="SELECT * FROM user WHERE id = '".$q."' and fecha = '".$fecha."'  ";
  14.  
  15. $result = mysql_query($sql);
  16.  
  17. echo "<table border='1'>
  18. <tr>
  19. <th>Firstname</th>
  20. <th>Lastname</th>
  21. <th>Age</th>
  22. <th>Hometown</th>
  23. <th>Job</th>
  24. </tr>";
  25.  
  26. while($row = mysql_fetch_array($result))
  27.   {
  28.   echo "<tr>";
  29.   echo "<td>" . $row['FirstName'] . "</td>";
  30.   echo "<td>" . $row['LastName'] . "</td>";
  31.   echo "<td>" . $row['Age'] . "</td>";
  32.   echo "<td>" . $row['Hometown'] . "</td>";
  33.   echo "<td>" . $row['Job'] . "</td>";
  34.   echo "</tr>";
  35.   }
  36. echo "</table>";
  37.  
  38. ?>
Segun veo estas poniendo mal las comillas en:
xmlhttp.open("GET","getuser.php?q="+str&fecha="+fe cha, true);

Sería:
xmlhttp.open("GET", "getuser.php?q="+str+"&fecha="+fecha, true);
  #5 (permalink)  
Antiguo 04/05/2010, 12:00
 
Fecha de Ingreso: marzo-2010
Mensajes: 432
Antigüedad: 14 años, 1 mes
Puntos: 11
Respuesta: Como enviar mas valores al GET ya que solo acepta un solo valor

si funciona super bien el select al seleccionar envia el valor.

Pero no me carga la tabla cuando carga la pagina como lo puedo hacer ??

body onload o window.onload no me reconoce los parametros, solo me toma los parametros que provienen del select.

str debe de estar en 0 y las fechas son dinamicas.

Código Javascript:
Ver original
  1. showUser(str, fechaCalendario_1, fechaCalendario_2)
  2. {
  3.  
  4. }
  #6 (permalink)  
Antiguo 23/05/2010, 12:26
Avatar de SUMMITE  
Fecha de Ingreso: julio-2002
Mensajes: 19
Antigüedad: 21 años, 10 meses
Puntos: 0
Respuesta: Como enviar mas valores al GET ya que solo acepta un solo valor

no es por nada pero creo que te falla esto:

Código HTML:
xmlhttp.open("GET","getuser.php?q="+str&fecha="+fecha, true);
creo que tendfria que ser:

Código HTML:
xmlhttp.open("GET","getuser.php?q="+str+"&fecha="+fecha, true);
y la llamada q seguramente te falla es:

Código HTML:
 ="showUser('valor1','valor2');"

Última edición por SUMMITE; 23/05/2010 a las 12:38
  #7 (permalink)  
Antiguo 26/05/2010, 14:02
Avatar de MaRcElTeLlA  
Fecha de Ingreso: mayo-2010
Ubicación: Martorell
Mensajes: 66
Antigüedad: 14 años
Puntos: 5
Respuesta: Como enviar mas valores al GET ya que solo acepta un solo valor

La petición get acepta todos los valores que le quieras pasar hasta un límite de bytes que creo que son 512B?? puede?

Bueno, el caso es que 3 o 4 le puedes pasar sin problema

GET va por url, y su sintaxi es:


WWW.NOMBREDELDOMINIO.COM/index.php?variable1="hola"&variable2="adios"&varia ble3="yeah"

y así hasta que pete.


Bueno espero que te sirva :P

Etiquetas: ajax, enviar, mas
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 06:46.