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!';
?>

4 Answers 4

7

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.

Sign up to request clarification or add additional context in comments.

16 Comments

thanks for the answer, but the topic parameter is not echoing on the page, the page is loaded good though
@pingpong - After you change the order so it's before the # it's still not echoing?
@nick yeh i have changed the order, the page is loading okay expect the echo get part?
@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?
@pingpong - There's no topic being passed in your script...only the page parameter is set.
|
1

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

Comments

0

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

Comments

0

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
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.