У меня есть приложение. Когда пользователь нажимает кнопку «Добавить в корзину» или «Save Project» это вызывает соответствующий 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
На этом этапе вы можете посмотреть в фреймворк.Магистраль довольно проста в применении к существующему проекту, и если вы используете его [router] (http://backbonejs.org/#Router), вы получаете функциональность, которую вы ищете вне ворот. Однако есть еще вопрос, что произойдет, если пользователь обновит страницу. Тогда вы SOL, что бы вы ни выбрали. Возможно, вам также понадобится решение localStorage. – stakolee