本文介绍了获取哈希符号后的请求部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站有 AJAX 驱动的搜索,它使用深层链接.当用户点击链接时……

My web-site has AJAX-powered search, that uses deep-linking. When user follows a link …

http://example.com/articles#/?tags=Mac%20OS,review

... 标签Mac OS"和评论"应该已经在搜索表单中被选中,与Mac OS"和评论"相关的文章应该出现在页面上.

… tags "Mac OS" and "review" should already been selected in a search form and articles, related to "Mac OS" and "review" should be presented on the page.

我有以下情况,需要修复

I have following scenario, that a need to fix

  1. 用户点击链接http://example.com/articles#/?tags=Mac%20OS
  2. 在初始页面呈现期间,获取所有文章
  3. 在客户端,哈希部分被解析,并且只有Mac OS"相关的文章通过 AJAX 请求.
  4. 客户端接收Mac OS"-文章并替换在第 2 步获取的所有文章.它还在搜索表单上将Mac OS"标记标记为已选择.

这里的问题是重复的文章渲染,这对用户来说看起来真的很糟糕.他查看了所有文章,几秒钟后,它们将被替换为Mac OS"-文章.

The problem here - is duplicated articles rendering, that looks really bad for the user. He looks at all articles, and after couple of seconds, they will be replaced with "Mac OS"-articles.

我需要有以下场景:

  1. 用户点击链接http://example.com/articles#/?tags=Mac%20OS
  2. 服务器解析哈希部分并返回Mac OS"相关文章
  3. 客户明白,Mac OS"-文章已经存在并且什么都不做.它只是将Mac OS"标记标记为选中.

为此,我需要获取请求字符串的哈希部分:

To do this, i need to get hash-part of the request string:

/?tags=Mac%20OS

我不能在 ? 之后使用请求参数,因为我使用 AJAX 和深层链接.使用 ?-part,浏览器将被迫重新加载页面.我需要在不重新加载页面的情况下做任何事情.

I cannot use request parameters after ?, because i use AJAX and deep-linking. With ?-part, browser will be forced to reload the page. I need to do anything without reloading the page.

您的帮助将不胜感激.

谢谢.

推荐答案

哈希后的 URL 部分不会发送到服务器,因此您无法在那里对其进行处理.您可以在创建 Ajax 请求的客户端代码中提取该部分 URL,并将其作为参数发送.

The part of a URL after the hash is not sent to the server, so you can't process it there. You can extract that part of the URL in the client-side code that creates your Ajax request and send it as a parameter.

这篇关于获取哈希符号后的请求部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 09:34
查看更多