shortysbest Posted December 14, 2011 Share Posted December 14, 2011 I'm using the jQuery Address plugin for Hash URLs for my website as the main navigation system and I am trying to come up with a solution for loading in multiple pages through ajax (Ajax loading is not the problem). Here's what I'm trying to do: $.address.change(function(event) { var hash_value = event.value; //Hash value from the list of URLs before would be everything after "www.site.com/#" so for the first URL the result would be: "/home" // Okay, so this is how my URL looks: // www.site.com/#/home // www.site.com/#/profile/1 // www.site.com/#/profile/1/photos // www.site.com/#/profile/1/photos/album // www.site.com/#/profile/1/photos/album/82920 // etc, those are all of the URLs I will be using, and probably even more. (as far as levels of navigation, values can and will be different) //when the entire website first loads it should load the first level of the URL (home and profile from the URLs above) //since the data that needs to be return is JUST the name of the php file we have to split it to different parts to get different information to use to propogate the page. var uri = hash_value.split("/"); var page = uri[1] ? uri[1] : ''; // returns from the above URLs: "home" or "profile" var user_id = uri[2] ? uri[2] : ''; //returns from the above URLs: "1" var sub_page = uri[3] ? uri[3] : ''; //returns from the above URLs: "photos" //(This is how I'm doing it right now, however I'm sure there is a better way using "for each" or something a little more complex. //Now here's the part I need the most help with. //the first thing this should do is load the first page in the URL, so "home" or "profile" $.ajax({ type: "POST", url: "inc/"+page+".php", data: "id="+user_id, success: function(html){ $("#content").html(html); } }); //Now, after the first page loads, if there's another page in the URL to be loaded it should load, however it should not reload the previous page, entirely as well $.ajax({ type: "POST", url: "inc/sub_pages/"+sub_page+".php", data: "id="+user_id, success: function(html){ $("#sub_content").html(html); } }); //By now you should get the idea of what I'm trying to do }); Quote Link to comment https://forums.phpfreaks.com/topic/253145-jquery-address-hash-urls-multiple-levels-page-loading-structure/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.