在来自 php 的主题标签之后访问 URI 变量的最佳方法是什么? [英] What's the best way to access a URI variable after a hashtag from php?

查看:36
本文介绍了在来自 php 的主题标签之后访问 URI 变量的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Javascript 更新我的 URI 如下:

I have Javascript updating my URI as below:

/index.php?page=list#page=news

但我想让 page=news 以某种方式从我的服务器访问,以便在复制和粘贴 URI 时,它会转到新闻页面.这样做的最佳方法是什么?

But I would like to make page=news accessible somehow from my server so that when the URI is copied and pasted, it would go to the news page. What is the best way to do this?

我尝试了 $_SERVER['REQUEST_URI']$_SERVER 中存储的所有内容都在哈希标记之前.

I tried $_SERVER['REQUEST_URI'] but everything stored in $_SERVER is before the hash tag.

推荐答案

你不能.该数据称为片段,保留用于客户端处理,因此永远不会发送到服务器.

You can't. That data, called the fragment, is reserved for client side processing and thus is never sent to the server.

利用片段的唯一方法是在某个时候让 Javascript 进行干预.这可能意味着检查页面 onload 上的哈希标签,然后显示正确的数据.

The only way to utilize the fragment is to have Javascript intervene at some point. This probably means checking for a hash-tag on the page onload, and then displaying the proper data.

您可以通过 Javascript 加载整个页面.虽然它会杀死任何关闭 Javascript 的人的兼容性,但它会确保哈希标签最终被发送到 PHP

You could make your entire page loaded via Javascript. While it would kill compatability for anyone who turned off Javascript, it would ensure that the hash tag eventually gets sent to PHP

基本上,它看起来像这样:

Basically, it would look something like this:

  • PHP 发送页面
  • Javascript 读取 hastag
  • 使用标签参数创建 URL (loader.php?page=list&page=news)
    (注意在上面,page=list 将被 page=news 覆盖,所以 $_GET['page'] 将是 <代码>新闻.
  • 对 PHP 的 AJAX 调用
  • 将内容加载到 div 中.
  • PHP Sends Page
  • Javascript reads the hastag
  • Make a URL with a hashtag parameter (loader.php?page=list&page=news)
    (Note that in the above, page=list wil be overriden by page=news, so $_GET['page'] will be news.
  • AJAX call to PHP
  • Load the content into a div.

(这个问题是一个非常重复的问题)

(And this question is very much a duplicate question)

这篇关于在来自 php 的主题标签之后访问 URI 变量的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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