tags:

views:

72

answers:

4

i want to pass this paramater topic to another page,

p.s. the page is loaded using jquery?

the url:

http://localhost/final/home.php#page2?topic=jquery

now, i want to echo the the topic on #page2

<h3 class="timeline"><?php echo $_GET["topic"]; ?> </h3>

but it deosnt echo, any solutions, sorry for the newbiw questions :))

load_page.php

<?php
if(!$_POST['page']) die("0");

$page = (int)$_POST['page'];

if(file_exists('pages/page_'.$page.'.php'))
include('pages/page_'.$page.'.php');  // i.e page_2.php

else echo 'There is no such page!';
?>
+7  A: 

Your URL needs to be like this:

http://localhost/final/home.php?topic=jquery#page2

Anything after the hash (#) isn't sent by the browser, it's purely for the browser, e.g. scrolling to the correct location, a way to do AJAX history, etc...but it's not sent in the request, currently all your server is getting is:

http://localhost/final/home.php

Which explains why _GET["topic"] is empty.

Nick Craver
thanks for the answer, but the topic parameter is not echoing on the page, the page is loaded good though
pingpong
@pingpong - After you change the order so it's before the `#` it's still not echoing?
Nick Craver
@nick yeh i have changed the order, the page is loading okay expect the echo get part?
pingpong
@pingpong - Do you have a test page I can see? Also your question has me a bit worried...does the page literally have a `#` in the file name?
Nick Craver
nope it deosnt pages are in the format `page_2.php` and the jquery syntax is here http://pastie.org/1176477
pingpong
How is the Pastie snippet related to the problem you describe? I can see no reference to `home.php` or `topic` :-?
Álvaro G. Vicario
@pingpong - There's no `topic` being passed in your script...only the `page` parameter is set.
Nick Craver
@nick thanks but more `pages` access this script, i only need to pass topic parameter with this page(page 2), do you have a solution for that? sorry im such a dumbass
pingpong
@pingpong - Your `loadPage()` function can look like this: http://pastie.org/1176491 if something doesn't pass a topic parameter, that's fine it'll just be empty.
Nick Craver
thank you @nick, its still not echoing the topic value, i think your solution is right, but its obviously something wrong with the load_php.php, the ajax page, ive put in the the question above! thanks again
pingpong
@pingpong - If you're posting you need `$_POST["topic"];` for the echo, since it's a POST and not a GET happening.
Nick Craver
@nick thanks nick i tried the post, its working but it says undefined!! instead of the value of topic, shall i put the topic value in the link or as an id ?? :)))
pingpong
@pingpong - Make sure you're passing the topic into the `loadPage()` function, wherever it comes from, I'm not certain where the topic is coming from or I wouldn't have put a note on that in the update pastie.
Nick Craver
im so confused i hate jquery now!!! thanks anyway
pingpong
but the topic is coming from the url!! where else could come from!
pingpong
Nick Craver
i tried that aswell, its not working, im just gonna ask another question, don't worry you have helped enough for today, thank u your a star @nick
pingpong
A: 

To practical effects, a URL ends at #. Anything else is not even sent tot he server.

You probably want this:

http://localhost/final/home.php?topic=jquery#page2
Álvaro G. Vicario
A: 

remove the php from dataType, and read this read this about datatypes for ajax requests

getaway
A: 

Just use PHP's parse_url function to do something like this:

$url = 'http://username:password@hostname/path?arg=value#anchor';
//Replace the URL in your case with "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]

print_r(parse_url($url));

echo parse_url($url, PHP_URL_PATH)

Which will return:

Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)
/path

In your case it would be more like:

Array
(
    [scheme] => http
    [host] => localhost
    [path] => /final/home.php
    [query] => topic=jquery
    [fragment] => page2
)
Nitroware