Global Ajax Events ajaxSend, ajaxSuccess, ajaxError and ajaxComplete do not work
by ranadheemachineni
HTML
<div>
<input id="AjaxTestButton" type="button" name="ajaxtestbutton" value="Start Ajax Test"/>
</div>
<div>
Loaded by ajax request:
<div id="AjaxResponse">
</div>
</div>
CSS
/*!
* Load Awesome v1.1.0 (http://github.danielcardoso.net/load-awesome/)
* Copyright 2015 Daniel Cardoso <@DanielCardoso>
* Licensed under MIT
*/
.la-ball-spin-fade,
.la-ball-spin-fade > div {
position: relative;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.la-ball-spin-fade {
display: block;
font-size: 0;
color: #fff;
}
.la-ball-spin-fade.la-dark {
color: #333;
}
.la-ball-spin-fade > div {
display: inline-block;
float: none;
background-color: currentColor;
border: 0 solid currentColor;
}
.la-ball-spin-fade {
width: 32px;
height: 32px;
}
.la-ball-spin-fade > div {
position: absolute;
top: 50%;
left: 50%;
width: 8px;
height: 8px;
margin-top: -4px;
margin-left: -4px;
border-radius: 100%;
-webkit-animation: ball-spin-fade 1s infinite linear;
-moz-animation: ball-spin-fade 1s infinite linear;
-o-animation: ball-spin-fade 1s infinite linear;
animation: ball-spin-fade 1s infinite linear;
}
.la-ball-spin-fade > div:nth-child(1) {
top: 5%;
left: 50%;
-webkit-animation-delay: -1.125s;
-moz-animation-delay: -1.125s;
-o-animation-delay: -1.125s;
animation-delay: -1.125s;
}
.la-ball-spin-fade > div:nth-child(2) {
top: 18.1801948466%;
left: 81.8198051534%;
-webkit-animation-delay: -1.25s;
-moz-animation-delay: -1.25s;
-o-animation-delay: -1.25s;
animation-delay: -1.25s;
}
.la-ball-spin-fade > div:nth-child(3) {
top: 50%;
left: 95%;
-webkit-animation-delay: -1.375s;
-moz-animation-delay: -1.375s;
-o-animation-delay: -1.375s;
animation-delay: -1.375s;
}
.la-ball-spin-fade > div:nth-child(4) {
top: 81.8198051534%;
left: 81.8198051534%;
-webkit-animation-delay: -1.5s;
-moz-animation-delay: -1.5s;
-o-animation-delay: -1.5s;
...
JavaScript
$(document).ready(function() {
jQuery('body').ajaxStart(function(){
alert( "ajaxStart" );\
$('.la-ball-spin-fade').show();
}).ajaxStop(function(){
alert( "ajaxStop" );
}).ajaxSend(function(){
$('.la-ball-spin-fade').show();
}).ajaxComplete(function(){
alert( "ajaxComplete" );
}).ajaxError(function(){
alert( "ajaxError" );
}).ajaxSuccess(function(){
alert( "ajaxSuccess" );
});
$('#AjaxTestButton').click(function() {
var TestObj = new AjaxTest('');
TestObj.send();
});
});
AjaxTest = function(url) {
this.url = url;
}
AjaxTest.prototype = {
send: function() {
jQuery.ajax({
url: this.url,
timeout: 1000,
beforeSend: function(){ alert("zapme beforeSend"); },
success: function(data){
alert("success");
$('#AjaxResponse').html(data);
},
error: function(){ alert("error"); },
complete: function(){ alert("complete"); },
context: this
});
}
}