show loading message while loading contents in asp using jquery ajax

本小妞迷上赌 提交于 2019-12-02 11:36:06

Simple form of AJAX is the .get() method which should be enough for your needs.

First of all, add a placeholder in your HTML where the loading image will appear then when you have the contents loaded, those contents will be placed instead of the image.

For example:

<div id="ContentsPlaceholder"></div>

The jQuery code would now be:

$(function() {
    $("#ContentsPlaceholder").html("<img src='Loading.gif' />");
    $.get("GetData.asp", function(contents) {
        $("#ContentsPlaceholder").html(contents);
    });
});

This will put "Loading.gif" image in the placeholder then load data from page called "GetData.asp", and when the data is available it will put it instead of the image.

You can do that in this way:

$(function(){
    $('body').addClass('loading');
    $(window).load(function(){
      $('body').removeClass('loading');
      $('#wrapper').show(); // make display:none in the css.
    });
});

if you are using ajax then you can show it using .ajaxStart() and .ajaxComplete()

place it before ajax call:

$('#yourElem').ajaxStart(function() {
   $(this).addClass('loading');
});

Place this after ajax Call :

$('#yourElem').ajaxComplete(function() {
   $(this).removeClass('loading');
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!