Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在GET请求后更改显示的URL_Javascript_Html_Spring Mvc - Fatal编程技术网

Javascript 在GET请求后更改显示的URL

Javascript 在GET请求后更改显示的URL,javascript,html,spring-mvc,Javascript,Html,Spring Mvc,目前,我有两个基于以下URL的页面MyNewApp/purchase和MyNewApp/confirm。在第2页上,即“确认”,我添加了一个返回按钮,其中包含以下内容 HTML <button type="submit" class="btn" id="back"> Go Back </button> 按下后退按钮后,一切正常,但URL更改为/MyNewApp/backToPurchase?\u method=。按下后退按钮后,如何将URL设置为/MyNewApp/pu

目前,我有两个基于以下URL的页面
MyNewApp/purchase
MyNewApp/confirm
。在第2页上,即“确认”,我添加了一个返回按钮,其中包含以下内容

HTML

<button type="submit" class="btn" id="back">
Go Back
</button>

按下后退按钮后,一切正常,但URL更改为
/MyNewApp/backToPurchase?\u method=
。按下后退按钮后,如何将URL设置为
/MyNewApp/purchase

您不能随意更改URL。 想想看,如果你能像那样更改URL,那将是一个很大的安全问题


但是试着用POST代替,或者只是把用户发送到一个新页面,这样URL就会改变,你有很多选择来解决它,想想看。

这从技术上来说就是你问题的答案,尽管你可能想想找一个更好的方法来做你想做的事情


window.history.pushState(null,null,“/newURL”)

我建议使用一个更好的选项,而不是仅提交表单用于重定向,请使用以下选项:

$('#back').click(function() {// <-- selecting by id is much faster than selecting by attribute "id"
    location.href = '/backToPurchase'; // or '/purchase';
    // OR you can do the following :
    history.back(); //this will performs as you clicked the back btn from the browser
});

$('#back')。单击(function(){//是否尝试将
此.form.action
更改为
“购买”
?我有一个处理/购买的控制器,它将初始化整个表单。我只想用输入的信息返回到上一个表单。听起来好像你在尝试模拟浏览器的“后退”按钮。你考虑过使用
window.history.back()吗
返回上一页?该JS函数将触发表单初始化。我想我必须按照@Guy的建议将请求更改为
POST
我可以知道更好的方法吗?
$('#back').click(function() {// <-- selecting by id is much faster than selecting by attribute "id"
    location.href = '/backToPurchase'; // or '/purchase';
    // OR you can do the following :
    history.back(); //this will performs as you clicked the back btn from the browser
});