window.location.replace – POST版本?
window.location.replace()
可以向目标URL发出GET请求并替换浏览器“返回”历史记录。
是否有任何方法可以发出POST请求到目标URL并替换浏览器“返回”历史记录(有/没有jQuery是好的)?
目前使用以下代码发出POST请求,但它不会替换“后退”历史记录:
var actionForm = $('
你可能想做这样的事情。
$.ajax({ url: "your url here", type: "POST", data: { field1: "value1", field2: "value2", field3: "value3" }, success: function (response) { if (response.successFlag) { //Replace current location from the history via history API window.history.replaceState({}, 'foo', '/foo'); window.location = "url of target location here if you want to send a get request"; $("#form-id").submit();//if you want to post something up } } });
我想也许你也可以摆脱使用这种方法去除历史的需要。
要么
您可以使用以下内容从历史记录中替换当前页面的记录并提交表单。
window.history.replaceState({}, 'foo', '/foo'); $("#form-id").submit();
要么
您可以在下一页加载时使用以下代码,并且要从历史记录中删除下一页的记录:
window.history.replaceState({}, 'foo', '/foo');