enviar datos con el método ajax jquery
Frecuentes
Visto 42 equipos
0
I really appreciate your helps, please help me one more thing, i have the following code, can you pleae tell me where am i doing it wrong?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script>
<script>
function upd(str)
{
$.ajax({
type:'post',
url:'upld.php',
datatype:'html',
data:'fname='+str,
success:function(response)
{
$("#ee").load("upld.php");
}
});
}
</script>
</head>
<body>
<select name="nmae" id="nmae" onChange="upd(this.value)">
<option value="dd">dd</option>
<option value="cc">cc</option>
</select>
<div id="ee"></div>
and my upld.php file consists of :
<?php
$k= $_POST["game"];
echo $k;
?>
3 Respuestas
1
I think what you try to do is this:
function upd(str){
$.ajax({
type:'post',
url:'upld.php',
datatype:'text',
data:{'fname': str},
success:function(response)
{
$("#ee").text(response);
}
});
}
contestado el 28 de mayo de 14 a las 14:05
Thanks alot dude it worked finally, only because of "$("#ee").text(response); " - gomzy
1
In your PHP you looking for a POST variable 'game', the only POST variable you are sending though is 'fname'
data:'fname='+str,
$k= $_POST["game"];
switch the variables to match, or add the additional variable you are looking for
contestado el 28 de mayo de 14 a las 14:05
Yeah that was a dumm mistake it should be $k= $_POST["fname"] but it still did't worked for me - gomzy
1
There are two changes to be done in your ajax method:
datatype:'text', // as you are echoing text only so change it to "text"
data:{'fname':str}, // send object this way
contestado el 28 de mayo de 14 a las 14:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas jquery ajax or haz tu propia pregunta.
esto está mal:
data:'fname='+str
- Ehsan Sajjadhacer :
data:{'fname':str
} - Ehsan Sajjaddude but it still dosn't work! - gomzy
@user3682527 check you console what error you get when you select - Rakesh Shetty
@EhsanSajjad he is using html type, not json - Venzentx