Last active
January 17, 2019 11:01
-
-
Save semiherdogan/1a5f712bd8a939d966cb7395f1141a47 to your computer and use it in GitHub Desktop.
Ajax Loader JS
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
// 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