0

I really dont know why this isnt working!

<script src="js/jquery.js" type="text/javascript" language="javascript"></script>

<script type="text/javascript">

function updateVAL()
{
var f = document.getElementById("nu");
var val=f.value;
alert(val); // it displays the value properly 
$.post("getDATA.php", {id: val}); // I sent the variable with jquery
}

</script>

getDATA.php

$value=$_POST['id'];
echo $value;

and when I access getDATA.php to see if it was sent I get this:

Notice: Undefined index: id in C:\Users\dan...

why the variable 'id' isnt set ? why is isnt passed to the server ?

Any help would be appreciated :) Cheers,

dan.

14
  • What does val contain? Commented Aug 30, 2011 at 6:21
  • When you say when I access getDATA.php to see if it was sent do you mean via Firebug or Web Inspector? Commented Aug 30, 2011 at 6:24
  • 1
    I'm not sure about this, but did you try to put quotes in id? Like this: $.post("getDATA.php", {"id": val}); Commented Aug 30, 2011 at 6:26
  • try putting $_POST['id'] to some file instead of echo. i guess you will see it. Commented Aug 30, 2011 at 6:26
  • 1
    I access getDATA.php by the url Commented Aug 30, 2011 at 6:35

1 Answer 1

3

Parameters are being sent via ajax - so this js script calls getDATA.php and $_POST['id'] is "seen" there only at that time.

And you are trying to access getDATA.php after and send no post or get parameters by your briwser - so you don't see this params there.

You have to catch echo by your js script. Look at this demo:

$.post("test.php", { name: "John", time: "2pm" },
   function(data) {
     alert("Data Loaded: " + data);
   });
Sign up to request clarification or add additional context in comments.

1 Comment

ohhh I understand now! I did what u said and the value was retrieved to js after it was echoed by getDATA.php many thx to u and all that helped :)

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.