Created
November 21, 2013 02:26
-
-
Save tomoyamkung/7575105 to your computer and use it in GitHub Desktop.
[JavaScript]Ajax 通信処理で失敗した responseText をログ出力する。
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 通信処理で失敗した responseText をログ出力する。 | |
* | |
* responseText には次の形式の JSON が設定されている想定。 | |
* | |
* { | |
* "errors" : [ | |
* エラーメッセージ1, | |
* エラーメッセージ2, | |
* エラーメッセージ3 | |
* ] | |
* } | |
* | |
* @param {XMLHttpRequest} xhr Ajax 処理失敗時に返ってくる XMLHttpRequest オブジェクト | |
* | |
*/ | |
function showErrorMessage(xhr) { | |
if(typeof window.console === "undefined") { | |
return; | |
} | |
var json = JSON.parse(xhr.responseText); | |
for(var i = 0, len = json.errors.length; i < len; i++) { | |
console.log(json.errors[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment