Mohammad Raha Mohammad Raha - 2 months ago 10
HTML Question

new idea to load page in full ajax pages

i have some problem with my site loading.
my site is a full ajax site so i need to a load page to show it when a button clicked or some thing like that. i create a

div
element with loading content and
show
it when buttons clicked and
hide
it when proccess end. but in fact the
loading div
hide before the new content loaded.

I use
$.ajax()
function to send and manage my requests to server.

how can i solve this problem ? help me if you have a good idea please.

Answer

Use below code that will be help you out.

$(document).ajaxStart(function () {
        $("#loaderdiv").css("display", "block");
    });

    $(document).ajaxComplete(function () {
        $("#loaderdiv").css("display", "none");
    });
    $(document).ajaxError(function () {
        $("#loaderdiv").css("display", "none");
    });