Created
September 7, 2016 05:31
-
-
Save kawa-/33d72748ce9b120c785f6f13b5b525b3 to your computer and use it in GitHub Desktop.
jQuery 3における ajax の書き方一例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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