我正在使用ajax函数来更新和输出结果。 如何在第二次更新结果再次显示之前延迟 2 秒? 因为现在,在第一次更新和第二次更新之后,文本是一样的 “已更新”我想让用户知道这是第二次更新消息。
$.ajax({
type: "post",
url: "function.php",
data: "ajax=updateAward&" + inputs,
success: function(html) {
$('#message_award').html(''); //clear previous text
//delay 2 sec then display below?
$('#message_award').html(html) ;
}
});
最佳答案
使用setTimeout
在延迟(以毫秒为单位)后执行函数。这是一个完整的示例:
$.ajax({
type: "post",
url: "function.php",
data: "ajax=updateAward&" + inputs,
success: function(html) {
setTimeout(function() {
$('#message_award').html(html);
}, 2000);
}
});
关于javascript - 如何在ajax函数中添加延迟函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19942636/