Pass data from jQuery to PHP for an ajax post

With jQuery post you can define a callback function which is executed when the data is returned:

$.post('/callcenter/admin/postContacts', data, function(returnedData) {
    // do something here with the returnedData
    console.log(returnedData);
});

The data should be in the form:

{name: 'value', anotherName: 'another value'}

which equates to the post names on the PHP end accessible in plain PHP like this:

echo $_POST['name'];           # prints "value"
echo $_POST['anotherName'];    # print "another value"

Leave a Comment