在 div 中插入一些文本后,我使用不起作用的重定向调用 setTimeout()
,我使用的脚本与我在另一个项目中使用的几乎相同的脚本确实有效,我不明白为什么?
有效的脚本
$.getJSON("http://newberylodge.co.uk/webapp/includes/login1.php",{username:childsname,password:password},function(json) {
if(json.result === "success") {
$("#add_err").html( "Welcome "+childsname+"!");
setTimeout(function(){
window.location= "menu.html";
},2000);
}else{
$("#add_err").html(json.message);
}
});
}
脚本不起作用
$.post("includes/addVolunteer.inc.php",{volunteerName:volunteerName,volunteerCity:volunteerCity, volunteerCounty:volunteerCounty,volunteerService:volunteerService,volunteerEmail:volunteerEmail},function(json) {
if(json.result === "success") {
$("#volunteerReport").html(json.message);
setTimeout(function(){
window.location= "view.htm";
},2000);
}else{
$("#volunteerReport").html(json.message);
}
});
}
我已经检查了控制台中的错误,但没有显示任何错误
最佳答案
你可以这样尝试
$.post("includes/addVolunteer.inc.php",{volunteerName:volunteerName,volunteerCity:volunteerCity, volunteerCounty:volunteerCounty,volunteerService:volunteerService,volunteerEmail:volunteerEmail},function(json) {
if(json[0] === "success") {
$("#volunteerReport").html(json.message);
setTimeout(function(){
window.location= "view.htm";
},2000);
}else{
$("#volunteerReport").html(json.message);
}
});
}
我不确定,但对你有帮助。
关于javascript - setTimeout 不起作用,尽管可以在另一个类似的脚本中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30396844/