获取用于在页面上加载 div 的 URI?

发布于 2024-09-25 18:52:09 字数 442 浏览 0 评论 0原文

我在通过 jQuery 的 .load() 函数加载的 PHP 生成的页面上有一个 div。该 div 包含一个已分页的长列表(第 1、2、3...25 页等的链接)。我想编写一个函数,它将保留 URI 的“搜索”部分中的变量(也就是说在 URI 的末尾:?foo=1&bar=pancakes)并粘贴在 &page= 上X在最后。然而,要做到这一点,我必须以某种方式检索从该 div 中加载该 div 的当前 URI。

window.location.search 显然只从父页面检索信息,所以这没有帮助。 .js 文件是静态加载的,因此我无法将 PHP 插入 Javascript 中间来设置变量。我什至无法将分页链接移到父页面中,因为当列表中的条目数发生变化时,我需要更新页数。我不知道如何完成这项任务。任何建议将不胜感激。

编辑:链接全部由 jQuery 处理,以使用新信息加载 div - 因此 .load()

I have a div on a PHP-generated page loaded through jQuery's .load() function. This div contains a long list which has been paginated (links for page 1, 2, 3... 25, etc.). I'd like to write a function which will preserve the variables in 'search' portion of the URI (which is to say at the end of the URI: ?foo=1&bar=pancakes) and stick on a &page=X at the end. However, to do that, I must somehow retrieve the current URI which loaded the div from within that div.

window.location.search obviously only retrieves information from the parent page, so that's no help. The .js files are loaded in statically, so I can't stick PHP into the middle of the Javascript to set variables. I can't even move the pagination links into the parent page, because I need the number of pages to update when the number of entries in the list changes. I'm at a loss as to how I might accomplish this task. Any suggestions would be greatly appreciated.

EDIT: The links are all handled by jQuery to load the div with the new information -- hence the .load()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

私野 2024-10-02 18:52:09

只需循环遍历 $_GET 变量即可:

function getvars_to_url_fragment() {
    $ret = "" ;
    $amp = "" ;
    foreach($_GET as $k => $v) {
        $ret .= $amp.urlencode($k)."=".urlencode($v) ;
        $amp = "&" ;
    }
    return $ret ;
}

Simply loop through the $_GET variable:

function getvars_to_url_fragment() {
    $ret = "" ;
    $amp = "" ;
    foreach($_GET as $k => $v) {
        $ret .= $amp.urlencode($k)."=".urlencode($v) ;
        $amp = "&" ;
    }
    return $ret ;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文