function countDown(secs){ $("#sucAppointment").html("预约成功,"+secs+"秒后返回首页"); if(--secs>0){ setTimeout("countDown("+secs+")",1000); }else{ location.href='/p2p'; } }
表单提交ajax方法
function addOnlineAppointment(){ var flag = true; if(checkTelphone()&&checkEmail()&&checkAmount()&&checkVerCode()){ $.ajax({ url:'${basePath}/p2p/addionlineAppointment.html',type:'POST',data:$("#onlineAppointmentForm").serialize(),success:function(data){ $("#sucAppointment").css("display","inline-block"); countDown(5); },error:function(data){ alert("似乎遇到了点儿麻烦,请刷新页面重试"); } }); }else{ flag = false; } }