1

在我的表单服务器端验证中,我使用history.go(-1);在验证错误的情况下重定向回来。这种方式表单数据保留在那里,用户可以修复数据并重新提交表单。

在我使用验证码之前效果很好。如果用户提交了错误的验证码,服务器验证会使用history.go(-1);. 这样,页面实际上并没有重新加载,验证码图像也不会刷新。所以用户不断提交错误的验证码。

那么每次页面通过history.go(-1);. 这样我就可以调用一个函数来重新加载验证码图像。

我必须这样做,因为我的表单处理是在单独的服务器上完成的。

谢谢。

4

4 回答 4

1

window.onpopstate就是你需要的。

于 2013-04-18T18:57:57.017 回答
1

您的解决方案是使验证码图像不可缓存。您需要指示您的验证码脚本发送带有图像的响应标头,可以是过去的“过期”日期,也可以是无缓存日期。这样,浏览器将在每个 history.go(-1) 上重新加载验证码。

于 2013-04-17T10:02:00.920 回答
0

我认为你需要一个历史适配器:

History.Adapter.bind (window, 'statechange', function () {});

这将在每次历史状态更改时触发该功能。

于 2013-04-17T10:03:31.313 回答
0
var url = location.href;
window.onpopstate = function(event) {
    if(url != location.href) {
        /*Your Function here
         * I'm using this to load the contentBox when user goes back or forward in  
         * browserhistory -- perfect for sites with ajax
         * works on all browser but u need Jquery. (Safari can't use window.location.href)
         * for functions to add dynamic params or removing them just ask ;)
         * define the url var to prevent function to fire on reload
         */
    }
};
于 2013-12-16T09:19:49.520 回答