window.location.replace-POST版本?

猛禽

window.location.replace() 可以向目标URL发出GET请求并替换浏览器的“后退”历史记录。

是否有任何方法可以发出针对目标URL的POST请求并同时替换浏览器的“后退”历史记录(使用/不使用jQuery都可以)?

当前使用以下代码来发出POST请求,但不能代替“返回”历史记录:

var actionForm = $('<form>', {'action': 'register.php', 'method': 'post'}).append($('<input>', {'name': 'action', 'value': 'user_register', 'type': 'hidden'}));
actionForm.appendTo('body').submit();
蔡卓妍

您可能想做这样的事情。

 $.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');

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

反应版本的 window.location.replace()?

在window.location.replace中使用参数

window.location.replace奇怪的行为

window.location =和window.location.replace()有什么区别?

window.location.assign()和window.location.replace()之间的区别

是否可以捕获window.location.replace事件?

Javascript window.location.replace只是重新加载了此页面

将变量放置在window.location.replace()内

关于window.location.href.replace的各种可能性

如何在jquery或javascript中使用window.location.replace

window.location.replace无法正常工作Laravel Ajax

本地存储和 window.location.href.replace

如果网址包含“#”,则不会触发window.location.replace(document.URL)在最后

window.location.replace在本地主机上不起作用

如何在AngularJS单元测试中模拟$ window.location.replace?

如果重新加载同一页面,则window.location.replace无法正常工作

如何使用window.location.href.replace切换href网址中的语言?

Phonegap-在我使用window.location.replace离开索引范围后处理推送通知

电子的remote.getGlobal()在window.location.replace()之后返回“未定义”

如何将查询字符串传递给window.location.replace()?

angularjs:在 window.location.replace 更改模板之前更新 ng-show

使用window.location.replace(“ xx”)重定向页面;根据条件

window.location.replace(); 不是在单击按钮时重定向页面

我在使用window.location.replace吗?(我也是在写命令吗?)

为什么 store 在写入 window.location.replace("/home") 时会重置数据;

JavaScipt window.location

window.open与window.location.href

jQuery $ .post window.location重定向在.done中不起作用

$ .post()如果后面有重定向,将不起作用:window.location.href =