简体   繁体   English

查明表单是否已提交或页面是否刷新

[英]Find out if the form was submited or the page was refreshed

I am using a form to search for some date. 我正在使用表格搜索日期。 The form uses GET method for date retrieval. 该表格使用GET方法进行日期检索。

<form action="" method="GET">
  ...
  <div id="search_button"><input type="submit" value={% trans 'Search' %} name="search"></div>
</form>

How could I know whether the submit button was pressed or the page was refresed? 我怎么知道是按下了提交按钮还是页面被刷新了?

If someone submits the form then there'll be parameters in the query string named after your form fields. 如果有人提交表单,则查询字符串中将存在以表单字段命名的参数。 Of course, if someone then refreshes that page, I'm not sure that you'd be able to tell the difference between that and a form-submit. 当然,如果有人随后刷新了页面,我不确定您是否能够分辨出该页面和提交表单之间的区别。

If it's important that you can tell the difference, you should probably alter the form to use POST. 如果您能分辨出差异很重要,则应该更改表格以使用POST。

It sounds like you are trying to cache the search results. 听起来您正在尝试缓存搜索结果。 If so, then you should try checking the cache instead. 如果是这样,则应该尝试检查缓存。

Switch from ' if (form.refreshed) { use cached results } ' to ' if (cache.exists(form.GET)) { use cached results } ' 从' if (form.refreshed) { use cached results } '切换到' if (cache.exists(form.GET)) { use cached results } '

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM