Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery 3における ajax の書き方一例
$.ajax({
type: "POST",
url: "api.php",
timeout: 10000,
cache: false,
data: {'hello': "world"},
dataType: 'json'
})
.done(function (response, textStatus, jqXHR) {
console.log(response);
if (response.status === "err") {
alert("err: " + response.msg);
} else {
alert("OK");
}
})
.fail(function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
alert("失敗: サーバー内でエラーがあったか、サーバーから応答がありませんでした。");
})
.always(function (data_or_jqXHR, textStatus, jqXHR_or_errorThrown) {
// done,failを問わず、常に実行される処理
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.