开发者

retrieving $_GET variable in jquery

开发者 https://www.devze.com 2022-12-12 13:10 出处:网络
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%20s开发者_JAVA技巧olve%20problems%20with%20oth

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%20s开发者_JAVA技巧olve%20problems%20with%20others%27%20code.

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?

(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).


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.

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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消