enviar datos con el método ajax jquery

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;


?>

preguntado el 28 de mayo de 14 a las 14:05

esto está mal: data:'fname='+str -

hacer :data:{'fname':str} -

dude but it still dosn't work! -

@user3682527 check you console what error you get when you select -

@EhsanSajjad he is using html type, not json -

3 Respuestas

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

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

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 or haz tu propia pregunta.