Mvram
Mvram

Reputation: 424

show div while load is executing in jquery

I'm trying to show a div that That indicates that the page is loading, for the load I use the jquery load event, however, the load div always stays on the page and there is no hidden end load, my code is this:

$("#mydiv").fadeIn("fast");
                $('#page').load('myphp.php', { 'data': id },function(){
                     $("#mydiv").fadeOut("fast");
                });

Upvotes: 2

Views: 1496

Answers (2)

Sudhanshu Jain
Sudhanshu Jain

Reputation: 534

you can use $('#page').ajaxStart(callback); and $('#page').ajaxStop(callback);. look here:

https://api.jquery.com/ajaxStart/

https://api.jquery.com/ajaxStop/

Upvotes: 0

khaverim
khaverim

Reputation: 3544

Hide the div when the document finishes loading via

$(document).ready(function() {
        $("#mydiv").fadeOut("fast");
    });

(include this code after the rest of your JS in the header), e.g.

  1. HTML headers
  2. JS/jQuery
  3. this^
  4. CSS link
  5. HTML body contents

Upvotes: 1

Related Questions