I need to redirect an Ajax call without letting the client know.
getPage.php is an application which returns html etc. for a given query.
getPage.php?hash=interesting-article-title and getPage.php?page=3 returns the same.
To avoid the client from having to cache both of these I would like getPage.php?hash=interesting-article-title to REDIRECT to getPage.php?page=3 via PHP header 301 and location.
I tried doing this and it returns nothing. The ajax call does not seem to want to be redirected.
Does anyone have any idea what could solve this double-cache problem?
I would like to use 301 redirects because they are cacheable. This way the browser would automatically call page=3 when it is told to fetch hash=insteresting-article-title.
Code examples:
function handleInit(event) {
if (event.path != "/") {
var hash = event.path.replace(/\//,"").replace(/\?/g,"");
getPage(hash);
currentState.hash = hash;
} else {
currentState.id = 1;
}
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
}
function chapter_forward() {
if (!freeze) {
freeze = true;
getPage(currentState.id - 1);
}
}
function ajax_data(id) {
return typeof(id) == "string" ? "hash=" : "page=";
}
function getPage(id) {
$.ajax({
method: "get",
url: getPage.php,
data: ajax_data(id) + id.toString(),
dataType: 'json',
timeout: 2000,
error: function() {
$("#space-3").html('40104 - Request Timeout');
},
complete: function() {},
success: function(result) {
handleContent(result);
}
});
}
The reason I need the redirect to happen is because I get the id from a HASH when the user uses his back and forth browser buttons.
When the user simply navigates back and forth I simply add +1 to the current id.
getPage.php returns something like this:
{"article_id":"3","hash":"music-in-your-ear","title":"Music in your ear.","html":"Blah blah article 3","modified":"Fri, 20 Mar 2009 02:46:00 GMT"}
Thanks!