[JavaScript]Ajax 通信処理で失敗した responseText をログ出力する。
/** | |
* 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