我有一个ajax脚本来发送数据。我想在数据发送/处理之前显示.coin-flip
3秒钟。一旦这3秒结束,数据将正常发送到flip-process.php,然后返回结果将显示成功。但目前速度非常快,我只能看到硬币在这里翻转(我想要显示的动画)。因此,我希望在处理ajax请求之前延迟3秒。我该怎么做?在处理之前延迟ajax请求3秒
这是我的ajax脚本。
<script type="text/javascript">
$(document).ready(function() {
$("#submit").click(function() {
var dataString = {
flip: $("#flip").val(),
amount: $("#amount").val(),
};
$.ajax({
type: "POST",
url: "flip-process.php",
data: dataString,
cache: true,
beforeSend: function(){
$("#coins").hide();
$(".coin-flip").show();
},
success: function(html){
$(".message").html(html).fadeIn();
$("#coins").show();
$(".coin-flip").hide();
}
});
return false;
});
});
</script>
使用的setTimeout方法为它 的setTimeout(函数(){//动作东西},3000); –