我有一个小问题与一个网站,我正在写,我希望任何人的帮助。
我在一个网站上实现了一个simpleCart,购买过程非常简单。
我想做的是让用户进入一个页面,在那里他可以填写一个表格,然后继续结帐。(我不希望用户仅仅为了购买一件物品而创建一个帐户和所有东西)
但我似乎不能把简单的价值推到另一页(我只需要总价)。
我尝试了以下几点:
所有这些我都没有运气,我会感激任何想法或帮助。
下面是我已经尝试过的一些代码:可以通过添加:或(javas) this.returnFormattedPrice(tempItem.getValue('price')来显示简单的购物车总数)
首先,我尝试在php会话中存储out:
在Page1上:
<?php session_start(); $_SESSION['variable_name'] = '<div class="simpleCart_total"></div>'; ?>在第2页:
<?php session_start(); echo $_SESSION['variable_name']; ?>
第二,我尝试使用:
以下是脚本代码:
`// JavaScript Documentfunction getCookie(NameOfCookie) {
if (document.cookie.length > 0) {
begin = document.cookie.indexOf(NameOfCookie+"="); if (begin != -1) {
begin += NameOfCookie.length+1; end = document.cookie.indexOf(";", begin); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(begin, end)); } } return null;
}
function setCookie(NameOfCookie, value, expiredays) {
var ExpireDate = new Date (); ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()); }
function delCookie (NameOfCookie) {
if (getCookie(NameOfCookie)) { document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } }
在第1页,我将设置cookie,在第2页,我将读取它,但将两者都设置为:<div class="simpleCart_total"></div>或(javas) this.returnFormattedPrice(tempItem.getValue('price') )
没有用(它不会储存总价)
所以如果有人有更简单的方法,我会很感激的。
提前感谢
艾哈迈德
发布于 2014-12-20 10:14:20
使用php会话的方式可能无法工作,请尝试以下操作。在所有页的顶部,您要在其中放置变量。
<?php
session_start();
if(isset($_SESSION['total_price'])){$total_price=htmlentities($_SESSION['total_price']);
echo ' The total price of all items in your cart is $'. $total_price.'<br />';
}
?>https://stackoverflow.com/questions/27563872
复制相似问题