Foros del Web » Programando para Internet » Javascript »

envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,true);

Estas en el tema de envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,true); en el foro de Javascript en Foros del Web. tengo la siguiente funcion <script type="text/javascript"> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari ...
  #1 (permalink)  
Antiguo 16/01/2011, 11:30
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,true);

tengo la siguiente funcion
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlht tp.responseText;
}
}
xmlhttp.open("GET","views/getuser.php?q="+str,true);
xmlhttp.send();
}
</script>


necesito pasarle 6 datos como lo hago ? tengo que centrarme en las dos siguientes linesas

xmlhttp.open("GET","views/getuser.php?q="+str,true);
function showUser(str)
  #2 (permalink)  
Antiguo 16/01/2011, 14:00
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

leete este articulo
  #3 (permalink)  
Antiguo 16/01/2011, 15:42
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: hola amigos del foro

Hola:

Tienes que fabricar la url con todos los parámetros, cada uno con el formato: variable=calor; y a lavez separados por el separador de parámetros "&"

url = "destino.php?q=" + str_q + "&k=" + str_k + "&n=" + n...

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #4 (permalink)  
Antiguo 16/01/2011, 20:37
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

segui el consejo de ustedes y lei

http://www.w3schools.com/ajax/tryit....e=tryajax_post

pero al ponerlo a correr no me funciona

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp .responseText;
}
}
xmlhttp.open("POST","demo_post.php",true);
xmlhttp.send();
}
</script>
</head>
<body>

<h2>AJAX</h2>
<form action="" method="POST">
<input name="a" type="text" id="a">
<input name="b" type="text" id="b">
<div id="myDiv"></div>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<p>Click the button several times to see if the time changes, or if the file is cached.</p>
</form>
</body>
</html>


al otro lado tengo

<?
$a=$_POST["a"];
$b=$_POST["b"];
$suma= $a+$b;
echo $suma;


?>


gracias por la atencion prestada
  #5 (permalink)  
Antiguo 16/01/2011, 22:31
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: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

Hola:

La línea de parámetros la tienes que fabricar como las cadenas de parámetros get (sin el "?") y pasarla como parámetro en la función:

Código:
ajax.send(aquí_van_los_parámetros);
Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #6 (permalink)  
Antiguo 17/01/2011, 08:00
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp .responseText;
}
}
xmlhttp.open("POST","demo_post.php",true);
xmlhttp.send(a,b);
}
</script>

en esta deben linea debe de ir xmlhttp.send(a,b);

yo envio dos input a y b
  #7 (permalink)  
Antiguo 17/01/2011, 08:31
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

no has sabido interpretar lo que te hemos sugerido
Cita:
xmlhttp.send('var1='+a+'&var2='+b);
  #8 (permalink)  
Antiguo 17/01/2011, 08:36
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

gracias isabelm por responserme

al otro lado en demo_post.php tengo pero no me estan llegando los parametros el resultado me sale 0

$a=$_POST["a"];
$b=$_POST["b"];
$suma= $a+$b;
echo $suma;
  #9 (permalink)  
Antiguo 17/01/2011, 08:40
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

un ejemplo practico

Cita:
xmlhttp.send('var1=5&var2=3);

$a=$_POST["var1"];
$b=$_POST["var2"];
$suma= $a+$b;
echo $suma; ' 8
  #10 (permalink)  
Antiguo 17/01/2011, 08:42
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: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

Cita:
Iniciado por Montes28 Ver Mensaje
gracias isabelm por responserme

al otro lado en demo_post.php tengo pero no me estan llegando los parametros el resultado me sale 0

$a=$_POST["a"];
$b=$_POST["b"];
$suma= $a+$b;
echo $suma;
Hola:

Con el envío de "IsaBelM" (Hola ), la recepción sería:

$a=$_POST["var1"];
$b=$_POST["var2"];

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #11 (permalink)  
Antiguo 17/01/2011, 08:45
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

isabel estoy haciendo lo que me dices

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp .responseText;
}
}
xmlhttp.open("POST","demo_post.php",true);
xmlhttp.send('var1=5&var2=3');
}
</script>
</head>
<body>

y en demo_post.php

$a=$_POST["var1"];
$b=$_POST["var2"];

$suma=$a+$b;

echo $suma;
  #12 (permalink)  
Antiguo 17/01/2011, 08:49
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

pero no me sale nada
  #13 (permalink)  
Antiguo 17/01/2011, 08:50
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

bien, y cual es el resultado??
edito: no se nada de php, pero si de esa manera se recogen las variables enviadas por post, me hace pensar que así es, ya que lo dices caricatos (gracias, seguro que tu has tenido que ver algo en mi nombramiento), ha de mostrar algún resultado.
  #14 (permalink)  
Antiguo 17/01/2011, 08:53
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

que estoy haciendo mal

tengo dos input y quiero enviarlos por post y que en un div me retorne el resultado

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp .responseText;
}
}
xmlhttp.open("POST","demo_post.php",true);
xmlhttp.send('var1=a&var2=b');
}
</script>
</head>
<body>

<h2>AJAX</h2>
<form action="" method="POST">
<input name="a" type="text" id="a">
<input name="b" type="text" id="b">
<div id="myDiv"></div>
<button type="button" onClick="loadXMLDoc()">Request data</button>
<p>Click the button several times to see if the time changes, or if the file is cached.</p>
</form>
</body>
</html>


$a=$_POST["var1"];
$b=$_POST["var2"];

$suma=$a+$b;
echo $suma;

no sale nada que estoy haciendo mal? gracias por responderme
  #15 (permalink)  
Antiguo 17/01/2011, 09:00
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

es que no estás recogiendo los valores de los textfield

Cita:
function loadXMLDoc()
{
a = document.getElementById("a").value;
b = document.getElementById("b").value;

xmlhttp.send('var1='+a+'&var2='+b);
  #16 (permalink)  
Antiguo 17/01/2011, 09:13
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 19 años, 11 meses
Puntos: 834
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

Para enviar por post hay que agregar esto después de open:
Código PHP:
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
Así:
Código PHP:
...
xmlhttp.open("POST","demo_post.php",true);
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
... 
  #17 (permalink)  
Antiguo 17/01/2011, 11:01
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

hice lo que me dijo isabelm

y no suma los valores

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
a = document.getElementById("a").value;
b = document.getElementById("b").value;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari


xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp .responseText;
}
}
xmlhttp.open("POST","demo_post.php",true);
xmlhttp.send('var1='+a+'&var2='+b);
}

</script>
</head>
<body>

<h2>AJAX</h2>
<form action="" method="POST">
<input name="a" type="text" id="a">
<input name="b" type="text" id="b">
<div id="myDiv"></div>
<button type="button" onClick="loadXMLDoc()">Request data</button>
<p>Click the button several times to see if the time changes, or if the file is cached.</p>
</form>
</body>
</html>


y en demo_post.php

$a=$_POST["var1"];
$b=$_POST["var2"];

$suma=$a+$b;
echo $suma;
  #18 (permalink)  
Antiguo 17/01/2011, 11:05
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 19 años, 11 meses
Puntos: 834
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

http://www.forosdelweb.com/3708923-post16.html
  #19 (permalink)  
Antiguo 17/01/2011, 11:08
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

hice lo que me dijiste Panino5001 y tampoco me suma los dos valores

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
a = document.getElementById("a").value;
b = document.getElementById("b").value;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari


xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp .responseText;
}
}
xmlhttp.open("POST","demo_post.php",true);
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
}

</script>
</head>
<body>

<h2>AJAX</h2>
<form action="" method="POST">
<input name="a" type="text" id="a">
<input name="b" type="text" id="b">
<div id="myDiv"></div>
<button type="button" onClick="loadXMLDoc()">Request data</button>
<p>Click the button several times to see if the time changes, or if the file is cached.</p>
</form>
</body>
</html>


y en demo_post.php


<?
$a=$_POST["a"];
$b=$_POST["b"];

$suma=$a+$b;
echo $suma;

?>
  #20 (permalink)  
Antiguo 17/01/2011, 11:15
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 19 años, 11 meses
Puntos: 834
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

Bueno, ahora omitiste el método send... (sólo tenías que agregar eso, no quitar el resto)
Código PHP:
<?php 
if(isset($_POST['var1'])){
$a=$_POST["var1"];
$b=$_POST["var2"];

$suma=$a+$b;
echo 
$suma;
exit;    
}
?>
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
a = document.getElementById("a").value;
b = document.getElementById("b").value;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari


xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp .responseText;
}
}
xmlhttp.open("POST","<?php echo basename($_SERVER['PHP_SELF']) ?>",true);
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send('var1='+a+'&var2='+b);
}

</script>
</head>
<body>

<h2>AJAX</h2>
<form action="" method="POST">
<input name="a" type="text" id="a">
<input name="b" type="text" id="b">
<div id="myDiv"></div>
<button type="button" onClick="loadXMLDoc()">Request data</button>
<p>Click the button several times to see if the time changes, or if the file is cached.</p>
</form>
</body>
</html>
  #21 (permalink)  
Antiguo 17/01/2011, 11:23
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

Panino5001 muchas gracias me ayudaste bastante

Etiquetas: envio
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 00:43.