June 2015
Intermediate to advanced
192 pages
4h 8m
English
jQuery abstracts the various progress reporting mechanisms of the underlying XMLHttpRequest object in a platform-agnostic way, giving you the ability to determine whether your request succeeded or failed. You do this by registering functions that the jQuery AJAX handler will invoke when an error occurs or the results are successfully loaded.
Here's doAjax rewritten to support getting notifications on failure, regardless of whether the event succeeds or fails:
function doAjax() {
$('#debug').html("loaded... executing.");
var request = {
call: "kf6gpe-7"
};
$.ajax({
type: "POST",
url: "/",
data: JSON.stringify(request),
dataType:"json",
})
.fail(function() {
$('#debug').append("<br/>failed"); ...Read now
Unlock full access