我需要重定向Ajax调用,而不让客户机知道。
getPage.php是一个为给定查询返回html等的应用程序。
getPage.php?hash=interesting-article-title和getPage.php?page=3返回相同的内容。
为了避免客户机不得不缓存这两个方面,我希望getPage.php?hash=interesting-article-title通过PHP 301和location重定向到getPage.php?page=3。
我试过这样做,结果却一无所获。ajax调用似乎不希望被重定向。
有人知道什么能解决这个双缓存问题吗?
我想使用301重定向,因为它们是可缓存的。这样,当被告知要获取hash=insteresting-article-title.时,浏览器将自动调用page=3。
代码示例:
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);
}
});
}
我需要重定向的原因是,当用户使用他的来回浏览器按钮时,我从散列中获得id。
当用户只是来回导航时,我只需将+1添加到当前id中。
getPage.php返回如下内容:
{"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"}谢谢!
发布于 2009-03-25 00:31:41
发布于 2009-03-25 00:58:42
如果您正在使用apache,那么mod重写和重写映射文件是解决此服务器端问题的最佳方法,前提是您的散列是映射到指定is的一个预定义的术语列表。
我假设你这样做是为了SEO的好处?
https://stackoverflow.com/questions/679782
复制相似问题