show loading message while loading contents in asp using jquery ajax

拟墨画扇 提交于 2019-12-02 17:02:30

问题


In my asp site i'm trying to fetch user details from Active directory on page load. I like to show "loading.gif" image untill I get details. Could some help me as i'm new to jquery


回答1:


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.




回答2:


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');
});


来源:https://stackoverflow.com/questions/14219755/show-loading-message-while-loading-contents-in-asp-using-jquery-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!