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;


?>
5
  • this is wrong: data:'fname='+str Commented May 28, 2014 at 13:04
  • 1
    do :data:{'fname':str} Commented May 28, 2014 at 13:04
  • dude but it still dosn't work! Commented May 28, 2014 at 13:07
  • @user3682527 check you console what error you get when you select Commented May 28, 2014 at 13:09
  • @EhsanSajjad he is using html type, not json Commented May 28, 2014 at 13:13

3 Answers 3

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);  
       }
   });
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot dude it worked finally, only because of "$("#ee").text(response); "
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

1 Comment

Yeah that was a dumm mistake it should be $k= $_POST["fname"] but it still did't worked for me
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.