Javascript 刷新页面,无需重新发送 POST 数据(ASP.NET)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13986263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refresh a page, without resending POST data(ASP.NET)
提问by Mr Lonely
How to refresh and reload the page without resending the POST data?
如何在不重新发送 POST 数据的情况下刷新和重新加载页面?
I have tried location.reload()which works absolutely fine on Chrome(which was the testing environment while development). But IE and Firefox went into an Infinite Loop in JS - reposting a lot of junk/duplicate data.
我试过location.reload()在 Chrome 上运行得非常好(这是开发时的测试环境)。但是 IE 和 Firefox 在 JS 中陷入无限循环——转发大量垃圾/重复数据。
Note: However, I just want to refresh the page to clear all the form contents. I am also registering a start up script after Submit, that will show the alert message that data was added successfully.
注意:但是,我只想刷新页面以清除所有表单内容。我还在提交后注册了一个启动脚本,它将显示数据已成功添加的警报消息。
HELP!
帮助!
回答by karaxuna
Try this:
尝试这个:
window.location.href = window.location.href;
回答by Junnan Wang
location.href = location.href + '?' + Math.random();
This should work.
这应该有效。
回答by Ryan McDonough
In your code add:
在您的代码中添加:
Response.Redirect(Request.RawUrl)
回答by webnoob
If you just want to clear the form, why not:
如果您只想清除表单,为什么不:
<input type="reset" value="Clear Fields">
You could also do it using:
你也可以使用:
document.getElementById('<%=form1.ClientID%>').reset();
Seems a waste to reload the page unless you need to do something else as well.
除非您还需要做其他事情,否则重新加载页面似乎是一种浪费。
回答by Mamun
Add the following:
添加以下内容:
Server.Transfer(Request.RawUrl);
Server.Transfer(Request.RawUrl);
回答by M. A. R. Bin Siddiqui Mamun
The following will solve your problem:
以下将解决您的问题:
Server.Transfer(Request.RawUrl);
回答by tobspr
use location.reload(true). This "hard" reloads the page ..
使用location.reload(true). 这个“硬”重新加载页面..
回答by Remi Morin
I've try reload too, and reload(true) both not exactly doing what I wanted.
我也尝试过重新加载,并且重新加载(真)都没有完全按照我想要的方式进行。
I've seen that Location Object have other method (than reload) since I wanted to request the page in "get" I just did:
我已经看到 Location 对象有其他方法(而不是重新加载),因为我想在“get”中请求页面,我刚刚做了:
location.assign(window.location);
So far seem to be doing what I want, reload the same page without submitting again values. My use case is an ajax call to the server when session has expired. I display an error message saying that the session is lost, then I want the page to reload.
到目前为止似乎正在做我想做的事情,重新加载同一页面而无需再次提交值。我的用例是会话过期时对服务器的 ajax 调用。我显示一条错误消息,指出会话丢失,然后我希望重新加载页面。
回答by Israel
Simple way:
简单的方法:
history.replaceState(null, document.title, location.href)

