开发者

Pagination techniques for search results from large forms

开发者 https://www.devze.com 2023-01-06 02:43 出处:网络
When creating search forms in web pages, I generally use the GET method. This allow the results to be URI Addressable. It also makes for easy pagination of results in the standard manner.

When creating search forms in web pages, I generally use the GET method. This allow the results to be URI Addressable. It also makes for easy pagination of results in the standard manner.

But what about a form with a large number of options and fairly long field names? Using a GET request means that the URL of the results page can actually crack the practical URL length limit of 2KB.

If I change to using POST, I 开发者_如何学Gobeat the URL length limit. But then I lose the URI addressability. Also, all pagination links need to be reimplemented as little subforms with all the search parameter data stored in hidden fields; making these operate as links would then require something like onclick handlers, which makes them usable only when client-side scripting is enabled.

So, what is the advice for long search forms that:

  • maintain URI addressability
  • allow reasonable pagination links
  • don't break a practical URL 2KB length limit

The only thing I'm coming up with is sticking with GET, but reducing the lengths of the field names so that we are less likely to bust the URL limit.

Whaddya think? Many thanks in advance.


What you need to do is use the post method - you can't get around this if your URL is going to be over the limit (although you can delay the inevitable by abbreviating names and values).

Take the post and then redirect the client to a get, to keep things addressable you can either store the search server side against a key and retrieve it on the get (e.g. from memory or a database), or you could encode the keys into a single querystring key or a smaller number of keys which capture the behaviour. The resulting response will be bookmarkable etc.

Pagination is easy enough - just look for the presence or absence of the navigation buttons in the form collection and respond accordingly.

0

精彩评论

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