javascript - Pause before JQuery AJAX post - Stack Overflow

Because the page I am working on is an intranet page, my AJAX call is very quick along with the respons

Because the page I am working on is an intranet page, my AJAX call is very quick along with the response. For usability purposes I'd like a short 1-2 sec pause to display a loading animation. Below is what I have tried but the animation is barely visible.

$(document).ready(function(){ 
    $('#wait').hide();
    $('#submitform').click(function(){
    $('#wait').show();
    $.ajax({
        type: "POST",
        url: "abs_newabs_check.asp",
        data: { StaffID: $("#suggest1").val() },
        success: callback
    });

});
});

function callback(data, status)
{
    $('#wait').hide();
    $("#ajaxdiv").html(data);
}

Because the page I am working on is an intranet page, my AJAX call is very quick along with the response. For usability purposes I'd like a short 1-2 sec pause to display a loading animation. Below is what I have tried but the animation is barely visible.

$(document).ready(function(){ 
    $('#wait').hide();
    $('#submitform').click(function(){
    $('#wait').show();
    $.ajax({
        type: "POST",
        url: "abs_newabs_check.asp",
        data: { StaffID: $("#suggest1").val() },
        success: callback
    });

});
});

function callback(data, status)
{
    $('#wait').hide();
    $("#ajaxdiv").html(data);
}
Share Improve this question asked Jan 15, 2010 at 8:41 tonyyebtonyyeb 7195 gold badges13 silver badges32 bronze badges 1
  • 2 "I want to make my application slower", what an interesting idea :-) – naivists Commented Jan 15, 2010 at 9:44
Add a ment  | 

3 Answers 3

Reset to default 5

I would have to suggesting thinking about a different way to add usability you are now slowing down your service to help users. What about using the Yellow Fade Technique That way you can show something has changed on the page and you are not slowing down your system.

Here is a related question that may help. Yellow fade Effect with JQuery

Add a setTimeout call to the callback function:

function callback(data,status) {
  setTimeout(function() {
    $("#wait").hide();
    $("#ajaxdiv").html(data);
  }, 1500);
}

nb. the data parameter will be passed into the anonymous function as a closure, if I'm not mistaken

Use setTimeout function

setTimeout("alert('5 seconds has passed.');",5000);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744311144a4567953.html

相关推荐

  • javascript - Pause before JQuery AJAX post - Stack Overflow

    Because the page I am working on is an intranet page, my AJAX call is very quick along with the respons

    7天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信