Jump to content

jQuery address: Hash URLs multiple levels, page loading structure


Recommended Posts

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


});


 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.