ajax request with post data + 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.");
});