简体   繁体   中英

Set page load Processing time

I add loading image in code that image loading till when the whole process is not completely done but how i know the page loading time because the processing time always change according to the data.

I have mention the time in my below javascript code.

<script>
$('#save').click(function() {
   $('#loading').html('<img src="./images/ima.png"> loading...');
   $.ajax({
      success : function(d) {
         setTimeout(function() {
            $('#loading').html('<img src="./images/images.png">');
         }, 2000);
      }
   });
});
</script>

Use complete to hide your loading image, instead of setout in ajax success method, this way loading image will be hidden once ajax request completes,irrespective of error or success.

<script>
      $('#save').click(function() {
       $('#loading').html('<img src="./images/ima.png"> loading...');
       $.ajax({
          success : function(d) {
             //handle success
          },
          error: function(xhr) { 
            // hanndle if error occurs 
           },

          complete: function() {
              //hide loading here
               $('#loading').html('<img src="./images/images.png">');
          }
       });
    });
 </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM