tags:

views:

243

answers:

3

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:


In JS file:
$.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...

+2  A: 

Try this and see if you get any info.

$.post("setData.php", { myPOSTvar: "myData" },
    function(data){
        alert("Data saved");
});
Ólafur Waage
A: 

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

Kobi
A: 

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".

Ionuț G. Stan