post data using ajax in php code example
Example 1: ajax jquery post php
$.ajax({
url : "file.php",
method : "POST",
data: {
action : action ,
key_1 : value_key_1,
key_2 : value_key_2
}
})
.fail(function() { return false; })
.done(function(data) {
console.log(data);
});
Example 2: how to send data using ajax in php
$.ajax({
url: "/something",
type: "GET",
data: {p1: "This is our data"},
success: function(data){
console.log(data);
}
}).done(function(){
console.log("Success.");
}).fail(function(){
console.log("An error has occurred.");
}).always(function(){
console.log("Complete.");
});
Example 3: ajax post example php
var values = $(this).serialize();
$.ajax({
url: "test.php",
type: "post",
data: values ,
success: function (response) {
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});