I am making an all ajax site and loading my pages with jQuery's .load(). I am also changing the URL when I load a new page so my account url would look something like this : http://mysite.com/#!/account/ and my home screen looks like this http://mysite.com/#!/. This is the code I am using currently:
var oldLoc = window.location.hash.replace(/^#\!/,"");
if (oldLoc == '/account/') {
$('#reload_section').load('account.php');
} else if (check for other urls) {
}
This works fine until I throw my search in there. When a user submits a search form, the url changes to this http://mysite.com/#!/search/objects/Query Here where objects has 2 values objects and files. How can I incorporate the regex to separate the search URL into three parts but then also works if it is just http://mysite.com/#!/accounts or http://mysite.com/#!/. Also, how can I find the search parameters like if I search for Taco Truck the url would reflect it as http://mysite.com/search/objects/taco%20truck/.
This is what I was thinking of using:
var oldLoc = window.location.hash.replace(/^#\!/,"");
var m = /([\/^\/]+\/)([^\/]+\/)([^\/]+)/.exec(oldLoc);
if (oldLoc == '/account/') {
$('#reload_section').load('account.php');
} else if (m[1] == '/search/') {
if (m[2] == 'objects/') {
currentQuery = 'objects';
} else if (m[2] == 'files/') {
currentQuery = 'files';
}
}
Thanks!!!
P.S. The reason I am asking so much in one thing is that the regex might break if I don't mention it.