How to show ajax loading gif animation while the page is loading?

There are many approaches to do this.
A simple way to do:

<div style="display:none" id="dvloader"><img src="https://stackoverflow.com/questions/1305260/loading.gif" /></div>

JS:

$(function() {
    $(".changepass").click(function() {
        $("#dvloader").show();
        $(".block1").load("views/changepass.template.php", function(){ $("#dvloader").hide(); });
        return false;
    });
});

Edited display:block to show() after suggestion from James Wiseman 🙂

Leave a Comment