how to pass php variable in ajax data code example
Example 1: passing data variable using ajax
var myVar = "test";
$.ajax({
url: "test.php",
type: "POST",
data:{"myData":myVar}
}).done(function(data) {
console.log(data);
});
Example 2: how to pass value from javascript to php using ajax
$.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.");
});