Morsusy2k Posted February 3, 2013 Share Posted February 3, 2013 Is it possible to do this: $(document).ready(function(){$('#content').load('test.php');}); With option to change the url of the page to eg. http://site.com/index.php?page=test.phpand when you copy that url to your address bar you get the same page with /test.php loaded into it? Link to comment Share on other sites More sharing options...
dsonesuk Posted February 3, 2013 Share Posted February 3, 2013 You would load content from php page like so $.get('test.php' , function(data) {$('#content').html(data);}); not sure, what you mean about the other questions? Link to comment Share on other sites More sharing options...
Morsusy2k Posted February 3, 2013 Author Share Posted February 3, 2013 (edited) 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 February 3, 2013 by Morsusy2k Link to comment Share on other sites More sharing options...
dsonesuk Posted February 3, 2013 Share Posted February 3, 2013 When the page loads check with if condition if $_GET['page'] is set with isset(), if true use php to add the value returned with $_GET to the jquey load function, if not load a default. Link to comment Share on other sites More sharing options...
Morsusy2k Posted February 3, 2013 Author Share Posted February 3, 2013 Can you explain a little bit more,cause i'm stuck :SThanks for helping Link to comment Share on other sites More sharing options...
dsonesuk Posted February 3, 2013 Share Posted February 3, 2013 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 More sharing options...
Morsusy2k Posted February 3, 2013 Author Share Posted February 3, 2013 (edited) 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 February 3, 2013 by Morsusy2k Link to comment Share on other sites More sharing options...
dsonesuk Posted February 3, 2013 Share Posted February 3, 2013 (edited) 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 February 4, 2013 by dsonesuk Link to comment Share on other sites More sharing options...
Morsusy2k Posted February 4, 2013 Author Share Posted February 4, 2013 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 Link to comment Share on other sites More sharing options...
dsonesuk Posted February 4, 2013 Share Posted February 4, 2013 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 More sharing options...
xhtmlchamps1 Posted February 4, 2013 Share Posted February 4, 2013 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 More sharing options...
dsonesuk Posted February 4, 2013 Share Posted February 4, 2013 WELL dah! we had already established that in the first post, its the best method to use that requires sorting out, thanks for stating the obvious. Link to comment Share on other sites More sharing options...
Morsusy2k Posted February 4, 2013 Author Share Posted February 4, 2013 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 More sharing options...
dsonesuk Posted February 4, 2013 Share Posted February 4, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now