I am using jquery and the getJSON method and I am wondering if there is a way to display a message saying loading before it loads my content. i know with the jquery ajax calls there is the before submit callbacks where you can have something but the getJSON only has like three options.
Any ideas?
Add this somewhere to your page:
<div id="loading" style="display:none">
<img src="/images/ajax-loader.gif" alt="Loader" /> Loading...
</div>
<script type="text/javascript">
$().ready(function() {
$("#loading").bind("ajaxSend", function() {
$(this).show();
}).bind("ajaxComplete", function() {
$(this).hide();
});
});
</script>
You can style the loader-div as you like, e.g Google Mail-like loader:
#loading
{
position:fixed;
_position:absolute;
top: 0;
left:47%;
padding:2px 5px;
z-index: 5000;
background-color:#CF4342;
color:#fff;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With