例如,如果我输入 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/