书签ASP。使用POST还是GET搜索结果?

时间:2022-02-08 15:11:38

Hey guys, I'd like a little help understanding how HTML forms work. It is my understanding that forms that use GET as their method submit name/value pairs for all fields within the form tags of said submission. However, if you take a look at the follow example from Google (and I've seen this in many other places too) and only use one of the fields on the form:

大家好,我想帮助大家理解HTML表单是如何工作的。我的理解是,使用GET作为方法的表单为上述提交的表单标签中的所有字段提交名称/值对。但是,如果您看一下谷歌中的下列示例(我在许多其他地方也见过),并且只使用表单上的一个字段:

http://books.google.co.uk/advanced_book_search

http://books.google.co.uk/advanced_book_search

Rather than being sent to a page with a name/value pair for each field of the advanced search page you are taken to a much cleaner looking URL:

而不是被发送到一个具有高级搜索页面的每个字段的名称/值对的页面,而是被带到一个更整洁的URL:

http://www.google.co.uk/search?tbo=p&tbm=bks&q=hitchiker&num=10

http://www.google.co.uk/search?tbo=p&tbm=bks&q=hitchiker&num=10

Despite all of the input fields on the advanced search page.

尽管在高级搜索页面上有所有的输入字段。


Onto my problem... My own advanced search page is quite large and at the moment is being POSTed to my search results page which is taking in the values and searching accordingly, no problems! However, I want my users to be able to bookmark/share their searches and in order to do this I need to have items being passed into the querystring but I don't want massive querystrings if I don't need them. If my user has only searched by a color for example then I want the URL to be something like search.aspx?color=red; If they're searching by color and size then search.aspx?color=red&size=large and so on. Is this possible?

在我的问题…我自己的高级搜索页面相当大,目前正在我的搜索结果页面上发布,它正在接受价值和搜索,没有问题!但是,我希望我的用户能够使用书签/共享他们的搜索,为了做到这一点,我需要将条目传递到querystring,但是如果我不需要,我不想要大量的querystring。例如,如果我的用户只通过颜色进行搜索,那么我希望URL类似于search.aspx?color=red;如果他们搜索的是颜色和大小,那么搜索。aspx?颜色= red&size =大等等。这是可能的吗?

To complicate things even further I'm using ASP.NET so it's not the easiest of things to create a form that uses GET though I do believe I have already found away around this.

为了使事情变得更复杂,我正在使用ASP。所以创建一个使用GET的表单并不容易,尽管我相信我已经找到了。

If you can give any advice or a nudge in the right direction, then thank-you! :)

如果你能给你任何建议,或者向正确的方向推动,那么谢谢你!:)

2 个解决方案

#1


2  

What you're suggesting should be easily possible if you conditionally check the querystring on the results page to ensure the key/value is there.

如果您有条件地检查结果页面上的querystring以确保键/值在那里,那么您所建议的应该是很容易实现的。

if(Request.QueryString["color"] != "")
{
    // Add color to the seach parameters
}

To create the GET request I would think you would need to POST back to your search form and redirect to the results form from there, dynamically adding key/values to the querystring as and when they are required. This Post/Redirect/Get design pattern is typically used with web forms to help with book marking.

要创建GET请求,我认为您需要返回到搜索表单,并从那里重定向到结果表单,动态地向querystring添加键/值,以及何时需要它们。这个Post/Redirect/Get设计模式通常用于web表单,以帮助图书标记。

#2


0  

If you want to share bookmarked searches between users, then you'll have to share the name/value querystring options in the posted URL. It sounds like you don't want to include the pair if one wasn't specified. That's easy, just dynamically build a querystring for pairs that the user HAS provided input for. So, when processing, loop through all input controls, and if a value was provided, append it to the querystring, or not.

如果您希望在用户之间共享书签搜索,那么您必须在已发布的URL*享名称/值querystring选项。如果没有指定一对,您似乎不希望包含它们。这很简单,只需动态地为用户提供输入的对构建一个querystring。因此,在处理时,循环遍历所有输入控件,如果提供了值,则将其附加到querystring,或者不添加。

#1


2  

What you're suggesting should be easily possible if you conditionally check the querystring on the results page to ensure the key/value is there.

如果您有条件地检查结果页面上的querystring以确保键/值在那里,那么您所建议的应该是很容易实现的。

if(Request.QueryString["color"] != "")
{
    // Add color to the seach parameters
}

To create the GET request I would think you would need to POST back to your search form and redirect to the results form from there, dynamically adding key/values to the querystring as and when they are required. This Post/Redirect/Get design pattern is typically used with web forms to help with book marking.

要创建GET请求,我认为您需要返回到搜索表单,并从那里重定向到结果表单,动态地向querystring添加键/值,以及何时需要它们。这个Post/Redirect/Get设计模式通常用于web表单,以帮助图书标记。

#2


0  

If you want to share bookmarked searches between users, then you'll have to share the name/value querystring options in the posted URL. It sounds like you don't want to include the pair if one wasn't specified. That's easy, just dynamically build a querystring for pairs that the user HAS provided input for. So, when processing, loop through all input controls, and if a value was provided, append it to the querystring, or not.

如果您希望在用户之间共享书签搜索,那么您必须在已发布的URL*享名称/值querystring选项。如果没有指定一对,您似乎不希望包含它们。这很简单,只需动态地为用户提供输入的对构建一个querystring。因此,在处理时,循环遍历所有输入控件,如果提供了值,则将其附加到querystring,或者不添加。