Skip to content

Instantly share code, notes, and snippets.

@kawa-
Created September 7, 2016 05:31
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawa-/33d72748ce9b120c785f6f13b5b525b3 to your computer and use it in GitHub Desktop.
Save kawa-/33d72748ce9b120c785f6f13b5b525b3 to your computer and use it in GitHub Desktop.
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