我有一个应用程序。当用户点击“加入购物车”或“保存项目”,它调用适当的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