jquery ajax application/json code example
Example 1: how to set json type jquery ajax
$.ajax({
type: "POST",
contentType: "application/json",
url: 'http://localhost:16329/Hello',
data: { name: 'norm' },
dataType: "json"
});
Example 2: jquery ajax json
$.ajax({
method: "POST",
url: "some.php",
dataType: "json",
data: {}
}).done(json => console.log(json));
Example 3: 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;
}
});