开发者

Find out if the form was submited or the page was refreshed

开发者 https://www.devze.com 2023-02-15 21:42 出处:网络
I am using a form to search for some date. The form uses GET method for date retrieval. <form action=\"\" method=\"GET\">

I am using a form to search for some date. The form uses GET method for date retrieval.

<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 th开发者_如何学Goe 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.


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 }'

0

精彩评论

暂无评论...
验证码 换一张
取 消