如何通过$ _GET在URL中接受井号? [英] How can I accept a hash mark in a URL via $_GET?

查看:339
本文介绍了如何通过$ _GET在URL中接受井号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,哈希标记(#)不会发送到服务器,因此似乎不太可能使用原始PHP来解析数据,例如下面的URL:

From what I have been able to understand, hash marks (#) aren't sent to the server, so it doesn't seem likely that I will be able to use raw PHP to parse data like in the URL below:

index.php?name=Ben&address=101 S 10th St Suite #301

我希望使用$ _GET数据预填充表单字段.我将如何使用Javascript(或jQuery)做到这一点,并且有一个后备的版本不会对那些不使用Javascript的人造成干扰吗?当前,如果存在哈希(通常在地址字段中),则此后的所有内容都不会解析或存储在$ _GET中.

I'm looking to pre-populate form fields with this $_GET data. How would I do this with Javascript (or jQuery), and is there a fallback that wouldn't break my form for people not using Javascript? Currently if there is a hash (usually in the address field), everything after that is not parsed in or stored in $_GET.

推荐答案

您可以按urlencode(在php中)或encodeURIComponent(在JavaScript中)那样对哈希进行编码.

You can encode the hash as you should urlencode(in php) or encodeURIComponent(in JavaScript).

哈希"不是请求的一部分,这就是您的脚本永远看不到它的原因.

The "hash" is not part of the request, which is why your script never sees it.

这篇关于如何通过$ _GET在URL中接受井号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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