Skip to content

Instantly share code, notes, and snippets.

@semiherdogan
Last active January 17, 2019 11:01
Show Gist options
  • Save semiherdogan/1a5f712bd8a939d966cb7395f1141a47 to your computer and use it in GitHub Desktop.
Save semiherdogan/1a5f712bd8a939d966cb7395f1141a47 to your computer and use it in GitHub Desktop.
Ajax Loader JS
// TODO: find js way
$.ajaxSetup({
beforeSend: function (xhr) {
ajaxLoader.show();
},
complete: function (xhr,status) {
ajaxLoader.hide();
}
});
let ajaxLoader = {
selectorId: 'ajaxLoader',
counter: 0,
show: function () {
this.counter++
document.getElementById(this.selectorId).style.display = 'block'
},
hide: function () {
this.counter--
if (this.counter == 0) {
document.getElementById(this.selectorId).style.display = 'none'
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment