关于jsp中使用history.go(-1);js不刷新的问题

来源:互联网 发布:做淘宝亏钱 编辑:程序博客网 时间:2024/05/21 22:46

jsp使用:

js脚本:

//表单提交保存function submitForm() {$.ajax({type : "post",url : "${ctx}/safety/.../updateSafeEduTrainSave.do",dataType : "json",data : $("#form").serialize(),success : function(msg) {if(msg == true){alert("更新成功");history.go(-1);}else{alert("更新失败");}}});}
html的form表单:

<form id="form" enctype="multipart/form-data" method="POST" >/*form表单的内容*/</form>
错误提示:

解决:

问题出在提交方式(Get/Post)上,如果使用Post提交,history.go(-1)返回会出现网页已过期的错误

实现页面跳转:表单提交时如果要使用history.go();方法的话建议表单提交方式用get方式提交表单、或者是超链接(默认是get提交方式)

 表单提交时如果要使用post方式提交的话请不要使用history.go()方法,使用重定向即可(location.href = ""; ),或ajax重新请求

另外还要注意浏览器的兼容问题