Created
October 9, 2013 18:44
-
-
Save hersonls/6906069 to your computer and use it in GitHub Desktop.
JavaScript: Listening all ajax events
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
!function ($) { | |
var logEvent = function(event) { | |
$('.notifier').append('<p>'+event+'</p>'); | |
} | |
$(document).ajaxStart(onStart) | |
.ajaxStop(onStop) | |
.ajaxSend(onSend) | |
.ajaxComplete(onComplete) | |
.ajaxSuccess(onSuccess) | |
.ajaxError(onError); | |
// declare callback functions | |
function onStart(event) { | |
logEvent('Loading...'); | |
} | |
function onStop(event) { | |
// logEvent(event); | |
} | |
function onSend(event, xhr, settings) { | |
logEvent('Iniciando.'); | |
} | |
function onComplete(event, xhr, settings) { | |
logEvent('Completed.'); | |
} | |
function onSuccess(event, xhr, settings) { | |
logEvent('Success!'); | |
} | |
function onError(event, xhr, settings, err) { | |
// logEvent(event, xhr, settings, err); | |
} | |
$.get( | |
'http://127.0.0.1:8000/ajax_content.html', | |
function(response) { | |
$('.placeholder').html(response); | |
}, | |
'html' | |
); | |
}(window.jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment