在JQuery AJAX发布之前暂停 [英] Pause before JQuery AJAX post
本文介绍了在JQuery AJAX发布之前暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因为我正在处理的页面是一个Intranet页面,所以我的AJAX调用与响应一起非常快。出于可用性目的,我希望暂停1-2秒,以显示加载动画。以下是我的尝试,但动画几乎看不到。
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);
}
推荐答案
添加一个setTimeout调用回调函数:
Add a setTimeout call to the callback function:
function callback(data,status) {
setTimeout(function() {
$("#wait").hide();
$("#ajaxdiv").html(data);
}, 1500);
}
nb。如果我没弄错的话,data参数将作为闭包传递给匿名函数
nb. the data parameter will be passed into the anonymous function as a closure, if I'm not mistaken
这篇关于在JQuery AJAX发布之前暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文