开发者

Use HTML form to alter url loaded after submit

开发者 https://www.devze.com 2023-03-22 12:53 出处:网络
I have a search page, written in PHP, that gets its search terms from the URL, using $_GET (I\'m not sure of the terminology).

I have a search page, written in PHP, that gets its search terms from the URL, using $_GET (I'm not sure of the terminology).

I wanted to make the search term editable on that page. I added some checkboxes, one for each tag that could be chosen, and a submit button, but HTML forms send the data to the next page using $_POST, which isn't part of the URL, and is generally annoying if you want to reload the page, and get asked every time what if you want to resend data and stuff.

I want the search terms to always be represented in the URL, so you could just copy the URL to a new window, and you would get the same results, like Google does, but with checkboxes being turned into the parameters, instead of the search box. I think I could do this by having a secon开发者_如何学God page that gets sent the $_POST, which formulates a new URL, and redirects you, but that seems horrible. Is there any clean way to do this?


Set your form element method to GET:

<form method='get' ...


Yes, it's called AJAX. I think jQuery AJAX is muuuch easier than normal javascript so please look into this

Here is a simple example too.. also as many others are saying you can just change form method="get"

0

精彩评论

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