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

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

问题描述

例如,如果我输入 URL:

For example if I type in the URL:

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

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

Then on the server there is no part: #MOREURL

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

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

推荐答案

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

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

解释:
基本上页面 URL 的哈希组件(# 符号后面的部分)仅由浏览器处理 - 浏览器从不将其传递给服务器.遗憾的是,这是 HTML 标准的一部分,无论您使用的是 IE 还是任何其他浏览器(就此而言,PHP 或任何其他服务器端技术)都是一样的.

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:

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

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天全站免登陆