【发布时间】:2014-12-03 15:16:03
【问题描述】:
我有一个应用程序。当用户点击“添加到购物车”或“保存项目”时,它会调用相应的 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
});
}
我遇到的问题是,一旦用户位于项目页面或购物车页面并且他们点击后退按钮,它会将他们返回到带有空白项目的应用程序。我想要发生的是当他们点击后退按钮时,该项目被加载。
我不知道该怎么做...有什么想法吗?
【问题讨论】:
-
也许对历史进行了一些操作,以便您可以以某种方式引用要加载的项目?
-
此时您可能想要研究一个框架。 Backbone 很容易应用于现有项目,如果您使用它的router,您将获得您正在寻找的功能。但是,如果用户刷新页面,仍然会发生什么情况。那么无论你选择什么,你都是 SOL。您可能还需要一个 localStorage 解决方案。
标签: javascript