在jQuery中检索$ _GET变量 [英] retrieving $_GET variable in jquery

查看:115
本文介绍了在jQuery中检索$ _GET变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主页(topic.php),其中包含URL中的GET信息,例如:

I have a main page (topic.php) with GET information in the URL, like this:

http://studio.byuipt.net/topic.php?topic=Debugger&desc=Helps%20find%20and%20solve%20problems%20with%20others%27%20code.

我在topic.php中有一个div,"currLeader",我将另一个页面getCurrLeader.php加载到其中. getCurrLeader.php应该在URL的$ _GET信息中使用topic变量来进行mysql搜索并返回相关信息.问题是,尽管topic.php上的脚本能够成功使用extract($_GET),但是我无法从getCurrLeader.php extract($_GET)语句中检索任何变量.我以为两个页面都可以访问当前显示的URL.还有另一种方法可以从当前URL中获取此信息吗?

I have a div, "currLeader" in topic.php into which I load another page, getCurrLeader.php. getCurrLeader.php is supposed to use the topic variable in the $_GET info of the url to do a mysql search and return the relevant info. The problem is that while, scripts on topic.php are able to successfully use extract($_GET), I am not able to retrieve any variables out of the getCurrLeader.php extract($_GET) statement. I thought both pages would be able to access the currently showing url. Is there another way I can get this information out of the current url?

(因此,主题"信息实际上存在于页面上具有ID的元素中,我能够使用jquery成功地检索到它,但我想不出一种方法来解决这个问题,相同的文件,将该值传递给我的php脚本).

(consequently, the "topic" info is actually present in an element with an id on the page, and I'm able to successfully retrieve it using jquery, but I can't figure out a way to then, within the same file, pass that value to my php script).

推荐答案

我不确定我是否理解您的要求.初读时,我假设您正在尝试使用jquery进行此操作,但是现在我不确定我是否位于同一页面上.这是在javascript中提取参数的简单方法:

I'm not really sure I understand what you're asking. On first read I assumed you were trying to do this with jquery, but now I'm not so sure I'm on the same page at all. Here's an easy way to extract the parameters in javascript:

<script type="text/javascript">

var ourlocation = location.href;

var thisstuff = ourlocation.split("?");

var id = thisstuff[1];

var idary = id.split("&");

var param2 = idary[0];
var param3 = idary[1];
var param4 = idary[2];

</script>

这可能与您要尝试执行的操作无关.

Which probably has nothing to do with what you're trying to do.

在二读时,似乎您正在尝试在php脚本中获取原始URL,而另一个则是第一次加载.

On 2nd read it seems like you're trying to get the originating url in a php script, when another one loads first.

可以做到这一点的一种方法是使用会话.要么存储您要提取的参数,然后将它们填充到要由其他文件检索的会话中,要么实际上可以仅存储URL本身,然后将其拉出并拆分.

One way you could do that is use sessions. Either store the parameters you're trying to extract, and stuff them in a session to be retrieved by the other file, or you could actually just store the url itself, then pull it out and split it.

session_start(); 
$_SESSION['ourUrl'] = $_SERVER["REQUEST_URI"];

// do stuff on next page

unset($_SESSION['ourUrl']);

session_destroy();

如果上述任何方法都没有道理,请随时进行进一步解释,我们将看看是否可以帮助您.希望这会有所帮助.

If none of this makes sense feel free to explain further and we'll see if we can get you going. Hopefully this helps a little.

这篇关于在jQuery中检索$ _GET变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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