Jump to content

jQuery load and url's


Morsusy2k
 Share

Recommended Posts

Well the loading php page works like a charm with the code i added but that same #content div loads more pages. I would like to make it change address (url) when loaded. So it can be linkable. Eg. http://w3schools.invisionzone.com when loads this topic it turns into http://w3schools.invisionzone.com/index.php?showtopic=46574

Edited by Morsusy2k
Link to comment
Share on other sites

Something like

<?php$thisQSvalue="";if(isset($_GET['page']) && !empty($_GET['page'])){$thisQSvalue = $_GET['page']; }?>

$(function(){<?phpif($thisQSvalue != ""){?>$('#content').load('<?php echo $thisQSvalue; ?>');<?php}else{?>$('#content').load('test.php');  // can be default page<?php}?>});

have not tested it, but should work.

Link to comment
Share on other sites

I'm confused..So it should be like: Inside body tags:

 <?php$thisQSvalue="";if(isset($_GET['page']) && !empty($_GET['page'])){$thisQSvalue = $_GET['page']; }?>

And in jQuery script:

 $('#menubutton1').click(function(){<?phpif($thisQSvalue != ""){?>$('#content').load('<?php echo $thisQSvalue; ?>');<?php}else{?>$('#content').load('test.php');  // can be default page<?php}?>}); 

For every menu button..?

Edited by Morsusy2k
Link to comment
Share on other sites

You have 2 options(1) if the menu button is anchor link as in <a href="http://site.com/index.php?page=page1.php>page1</a><a href="http://site.com/index.php?page=page2.php>page2</a> etc, the page will reload, and php will read the page#.php, and jquery will load the page using the value passed to it. This only happens when page is reloaded, or when the user types the url with querysting to specific page.(2) on click of anchor links, read href address, strip out all but page1.php, retrieve href address and use that to load that specific pages content without reloading (you will have to use e.preventDefault() to prevent page reloading) of page. you may have to include both, one for when user enters url the address box, and when user clicks menu button.

Edited by dsonesuk
Link to comment
Share on other sites

I though it could be easier, like:if there is something after "site.com/" strip it and load it and if not continue with default,when clicked on a menu div (cause my menu buttons are actually divs) add page name to "site.com/" eg. "site.com/index.php?page=pagename" and load it (via jQuery without reloading).. If its complicated, and by your post i guess it is,its not the question between life and death :D

Link to comment
Share on other sites

If you are going this route, i should do it so it reloads the page with querystring, using $_GET['page'] code method to use in a php include within content, so that will take care of when js is disabled, then use jquery to prevent link forcing reload, read href, strip and search for 'page' querystring value, and then apply to load(). Note the non js method would be used for the first loading of page as well anyway, to check if user entered a querystring load that page content, if not! load default page content.

Link to comment
Share on other sites

yes it is possible you can run itcontent is the i.d of <div> and it displays the information with out refreshing.

Link to comment
Share on other sites

Okay so i have done a little searching and i found that i can use "$_GET["page"]" command to get what is typed in address bar. So i guess i can use it like this:

$('#content').load('<?php $_GET['page'] ?>');

(or i can make it into variable first) But how to add "?page=test.php" in the address bar when clicked on a button (without reloading) in php or javascript?

Link to comment
Share on other sites

Okay so i have done a little searching and i found that i can use "$_GET["page"]" command to get what is typed in address bar.So i guess i can use it like this:
$('#content').load('<?php $_GET['page'] ?>');

yes! but that only reads that when page is loaded or is reloaded, you click another link, the page reloads with new query string, $GET reads the new querystring and load() shows the content that matches that querystring value.
But how to [u]add[/u] "?page=test.php" in the address bar when clicked on a button (without reloading) in php or javascript?

PHP will always involve a reload, JavaScript can read from a php, as when using load(), $.get, $.post, ajax etc. but it will change specific page content. with changing the address, It can only be done with HTML5, and its not cross browser compatible, yet!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...