为什么URL的哈希部分在服务器端不可用? [英] Why is the hash part of the URL not available on the server side?

查看:220
本文介绍了为什么URL的哈希部分在服务器端不可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我输入网址:

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



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



可以发送或者将这些部分发送到没有jQuery AJAX的服务器上。

解决方案

不适用于浏览器,因此您必须使用Javascript进行处理。服务器无法读取它。



解释:

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



以下是 维基百科 所述的内容:


片段标识符的功能与URI的其余部分不同:即其处理独占客户端,不受服务器参与。当代理(如Web浏览器)从Web服务器请求资源时,代理将URI发送到服务器,但不发送片段。代理会等待服务器发送资源,然后代理会根据片段值处理资源。在最常见的情况下,代理将网页向下滚动到具有等于片段值的属性字符串的定位元素。其他客户行为是可能的



For example if I type in the URL:

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

Then on the server there is no part: #MOREURL

Is possible to send or get these part to the server without jQuery AJAX?.

解决方案

No, it is available to the browser only, so you have to deal it with Javascript. The server can not read it.

Explanation:
Basically the hash component of the page URL (the part following the # sign) is processed by the browser only - the browser never passes it to the server. This sadly is part of the HTML standard and is the same whether or not you are using IE or any other browser (and for that matter PHP or any other server side technology).

Here's what Wikipedia says about it:

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

这篇关于为什么URL的哈希部分在服务器端不可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆