Language: JavaScript
$.ajax() error handler
error: function(xhr, status) { var err = null; if (xhr.readyState == 4) { var res = xhr.responseText; if (res && res.substr(0,1) == '{') var err = JSON.parseWithDate(res); if (!err) { if (xhr.status && xhr.status != 200) err = new CallbackException(xhr.status + " " + xhr.statusText); else err = new CallbackException("Callback Error: " + status); err.detail = res; } } if (!err) err = new CallbackException("Callback Error: " + status); if (errorHandler) errorHandler(err, _I, xhr); }
Tags:
Description:
Getting a consistent error message from failures is a pain. XHR isn't fully available (causing all sorts of weird errors if readyState != 4 trying to access .status or responseText) when the request isn't complete yet for errors like timeout. If the server returned a JSON message great. Otherwise - not so much.
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

