php - 为什么 URL 的哈希部分在服务器端不可用?

标签 php javascript url hash href

例如,如果我输入 URL:

http://www.foo.com/page.php?parameter=kickme#MOREURL

然后在服务器上没有部分:#MOREURL

是否可以在不使用 jQuery AJAX 的情况下将这些部分发送或获取到服务器?

最佳答案

不行,它只对浏览器可用,所以你必须用 Javascript 来处理它。服务器无法读取。

解释:
基本上,页面 URL 的哈希部分(# 符号后面的部分)仅由浏览器处理——浏览器永远不会将其传递给服务器。遗憾的是,这是 HTML 标准的一部分,无论您是否使用 IE 或任何其他浏览器(以及 PHP 或任何其他服务器端技术)都是一样的。

这是 Wikipedia 是这样说的:

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server. When an agent (such as a Web browser) requests a resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the fragment value. In the most common case, the agent scrolls a Web page down to the anchor element which has an attribute string equal to the fragment value. Other client behaviors are possible

关于php - 为什么 URL 的哈希部分在服务器端不可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3664257/

相关文章:

php - 存储到数据库中 - 问题

javascript - 如何在套接字io中设置访问控制允许来源

java - 如何用所需的词而不是冗长的域名来屏蔽 URL?

javascript - 映射时嵌套数据表

ios - 如何在没有图像时隐藏 UIImageView 的 View

html - 用于查找不在超链接内的 URL 的正则表达式

php - 错误 'No route found' Symfony PHP

php - 子主题 css 不覆盖父主题

javascript - 如何在不影响其他参数值的情况下改变url参数值

php - 编写 PHP Web 服务的框架