最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set request parameters when you clicking on submit? - Stack Overflow

programmeradmin0浏览0评论

I have My request parameters in the URL of current page. When I click on submit in the same page, parameters lost got lost in the new request. How to retain the request parameters even after submitting the form?

I have My request parameters in the URL of current page. When I click on submit in the same page, parameters lost got lost in the new request. How to retain the request parameters even after submitting the form?

Share Improve this question asked Jul 28, 2011 at 4:21 galaxy3galaxy3 612 silver badges3 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

You can read the query params from the url and add them as a hidden fields into the form you are submitting. This will send the query string params along with the form.

  1. Send the request parameters as form's GET params
  2. Have the server set the parameters in a cookie so it is available in every page.
  3. Put it in browser's local storage.

If submitting the form via POST, you can include request parameters in the form's action attribute, eg

<form method="post" action="action?id=123&foo=bar">
<input type="text" name="baz">
<input type="submit">
</form>

What you are asking for is state management. It can be done in several ways

  1. HttpSession
  2. Cookies
  3. Hidden fields
  4. URL rewriting.

Hidden fields is an easy way to do it; although the HTML can get more lengthy. I personally prefer HttpSession.

发布评论

评论列表(0)

  1. 暂无评论