我有一個應用程序。當用戶點擊「加入購物車」或「保存項目」,它調用適當的URL來保存數據,然後將用戶重定向到正確的頁面:如何在用戶點擊後退按鈕時加載項目?
if (add_to_cart == true) //If we are adding to cart
{
$.ajax
(
{
//Note: tf_cart.module must contain $_POST['app'] $jpg = xmlp_f_save_jpg($_POST['file'], $_POST['app']);
type: "POST",
processData: false,
url: SITE_URL + "/system/atc/" + app_type + "/0/" + session_id + "/0/?prjid=" + project_id, //send data to this url
data: "xml=" + common_order_xml + "&prodid=" + product_id + "&file=" + image.src + "&rid=" + revision_id + "&cid=" + cart_id + "&app=html5" //send these as post variables to the url
}
).done(function(msg) //When we get a response from the server after we POST
{
//console.log("Project added to cart. "); //This is for testing the canvas element on screen - leave this code here
window.location = SITE_URL + "/cart/?pid=" + partner_id; //Send the user to the cart page
});
}
else //If we are saving the project
{
$.ajax
(
{
//Note: xmlproject.module must contain $_POST['app'] $jpg = xmlp_f_save_jpg($_POST['file'], $_POST['app']);
type: "POST",
processData: false,
url: SITE_URL + "/system/xml/import/" + app_type + "/" + session_id + "/?prjid=" + project_id, //send data to this url
data: "xml=" + common_order_xml + "&prodid=" + product_id + "&file=" + image.src + "&app=html5&rid=" + revision_id //send these as post variables to the url
}
).done(function(msg) //When we get a response from the server after we POST
{
var parser = new DOMParser(); //create a new DOMParser
var doc = parser.parseFromString(msg, "application/xml"); //convert the string to xml
pid = doc.getElementsByTagName('pid')[0].childNodes[0].nodeValue; //Get the pid (project id) from the xml
rid = doc.getElementsByTagName('rid')[0].childNodes[0].nodeValue; //Get the rid (revision id) from the xml
//console.log("Project saved. " + " pid=" + pid + " rid=" + rid); //This is for testing the canvas element on screen - leave this code here
window.location = SITE_URL + "/user/mystuff/projects/view/" + pid + "/?pid=" + partner_id; //Send the user to this project's page
});
}
我的問題是,一旦用戶或者是在項目頁面或購物車頁面,他們點擊返回按鈕,它將它們返回給應用程序,並返回一個空白項目。我想要發生的是當他們點擊後退按鈕時,該項目會被加載。
我不知道如何去這個...任何想法?
也許要加載的歷史記錄,以便你能以某種方式引用該項目的一些操作? – rfornal 2014-12-03 15:18:04
在這一點上,你可能想看看一個框架。Backbone可以很容易地應用到現有的項目中,並且如果使用其[router](http://backbonejs.org/#Router),則可以獲得所需的功能。但是,如果用戶刷新頁面,會發生什麼情況。然後,無論你選擇什麼,你都是SOL。您也可能需要localStorage解決方案。 – stakolee 2014-12-03 15:20:17