ajax syntax post request code example
Example 1: jquery ajax post example
var formData = {name:"John", surname:"Doe", age:"31"};
$.ajax({
url : "https://example.com/rest/getData",
type: "POST",
data : formData,
async : false,
success: function(response, textStatus, jqXHR) {
console.log(response);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
Example 2: how to set json type jquery ajax
$.ajax({
type: "POST",
url: siteRoot + "api/SpaceGame/AddPlayer",
async: false,
data: JSON.stringify({ Name: playersShip.name, Credits: playersShip.credits }),
contentType: "application/json",
complete: function (data) {
console.log(data);
wait = false;
}
});