0

I am trying to use an ajax 'POST' call through the jquery $.ajax function to send data to a php file. For some reason the callback is a success but the data is not getting to the php file. Here is an example of the code:

$.ajax({ type: "POST",
        url: "setData.php",
        data: "myPOSTvar=myData"
        success: function(){ alert("Data Saved"); } 
       });

In php file:

$var = $_POST['myPOSTvar']

$var ends up with a default value instead of the data it is sent.

Any ideas?

Sorry about the syntax errors...at work right now and don't have my code in front of me...the syntax is all correct in the actual script, just typed to quick when posting here...

3
  • Please repost your PHP code as I can't see anything. Commented Jan 29, 2009 at 14:38
  • If a request is made (and it does, because you say the php code is triggered), the problem is likely to be on your php. Commented Jan 29, 2009 at 14:52
  • It is getting a success, I just typed it wrong here... Commented Jan 29, 2009 at 15:17

3 Answers 3

1

Try this and see if you get any info.

$.post("setData.php", { myPOSTvar: "myData" },
    function(data){
        alert("Data saved");
});
Sign up to request clarification or add additional context in comments.

Comments

0

I doubt it's a success, the url should be a string : url: "setData.php" .

Comments

0

I really doubt that piece of JS code is working as it should. POST and setData.php should be enclosed with quotes. Right now you should get some errors because "POST" variable is not defined and then because you're accessing a "php" property on a non existent object "setData".

Comments

Your Answer

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