AJAX Forums

Shopping Cart help

This is a discussion on Shopping Cart help within the AJAX Help forums, part of the Beginners AJAX category; Hey there, i came across the shopping cart article on this site and would really lik to get this example working, however i am having some problems. Visual Studio is ...

Go Back   AJAX Forums > Beginners AJAX > AJAX Help

AJAX Made Easy

Old 04-19-2008, 04:40 PM   #1 (permalink)
Junior Member
 
Join Date: Apr 2008
Posts: 2
Rep Power: 0
jibber4568 is on a distinguished road
Shopping Cart help

Hey there, i came across the shopping cart article on this site and would really lik to get this example working, however i am having some problems.

Visual Studio is providing me with the following error for the default page

Code:
Warning	1	Error updating JScript IntelliSense: C:\inetpub\wwwroot\dragdroptest\prototype.js: Object doesn't support this property or method @ 548:35	C:\inetpub\wwwroot\dragdroptest\Default.aspx	1	1	C:\...\dragdroptest\
and the following error on the php page:

Code:
Error	2	XML document must contain a root level element.	C:\inetpub\wwwroot\dragdroptest\cart.php	30	3	C:\...\dragdroptest\
I have placed all the code into one page and then the php into its own page named cart.php as you can see below.

Any help would be much appreciated.

Cheers in advance.

Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ajax Workshop 3: Shopping Cart using Script.aculo.us</title>
<script src="prototype.js" type="text/javascript"></script>
<script src="scriptaculous.js" type="text/javascript"></script>
<style media="screen" type="text/css">
body {
	font-family:"Trebuchet MS";
	font-size:12px;
}
#cart {
	background-color:#FFFF66;
	border:dashed gray 1px;
	height:100px;
	width:500px;
	padding:5px;
	margin-top:10px;	
	overflow: auto;
}
#products {
	background-color:#FFF;
	border:dashed gray 1px;
	height:100px;
	width:500px;
	padding:5px;
}	
.box {
	background-color:#CCFF33;
	border:solid gray 1px;
	margin:10px;
	padding:4px;
	width:50px;
	height:50px;
	float:left;
	cursor:pointer;
}
#loading {
	display:none;
	float:right;
}
#clearCart {
	color:blue; 
	text-decoration:underline; 
	cursor:pointer; 
	float:right
}
#clearCart:hover {
	background-color:#CCFFCC;
	color:#000099;
}
</style>
<script language="javascript" type="text/javascript">
function addProduct(element, dropon, event) {
	sendData(element.id);
}
function sendData (prod) {
	var url    = 'cart.php';
	var rand   = Math.random(9999);
	var pars   = 'product_id=' + prod + '&rand=' + rand;
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onLoading: showLoad, onComplete: showResponse} );
}		
function clearCart () {
	var url    = 'cart.php';
	var rand   = Math.random(9999);
	var pars   = 'clear=true&rand=' + rand;
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onLoading: showLoad, onComplete: showResponse} );
}
function clearProduct (id) {
	var url    = 'cart.php';
	var rand   = Math.random(9999);
	var pars   = 'clearProduct=true&id=' + id + '&rand=' + rand;
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onLoading: showLoad, onComplete: showResponse} );
}				
function showResponse (originalRequest) {
	$('loading').style.display = "none";
	$('clearCart').style.display = "block";
	$('cart').innerHTML = originalRequest.responseText;
}
function showLoad () {
	$('clearCart').style.display = "none";
	$('loading').style.display = "block";
}
</script>
</head>

<body>
	<h1>Ajax Workshop 3: Shopping Cart using <a href="http://script.aculo.us">Script.aculo.us</a> </h1>
	<h2>Drag the products into the shopping cart</h2>
	<div id="products">
		<div style="float:left; font-weight:bold">Products</div>
		<div id="clearCart" onclick="clearCart();">Clear Cart</div>
		<div id="loading"><img src="padrino.jpg" alt="loading..." /></div>
		<br style="clear:both" />
		<div class="box" id="product_1">1</div>
		<div class="box" id="product_2">2</div>
		<div class="box" id="product_3">3</div>
		<div class="box" id="product_4">4</div>
		<div class="box" id="product_5">5</div>		
		<div class="box" id="product_6">6</div>				
	</div>
	<div id="cart">
		<div style="float:left; font-weight:bold">Shopping Cart</div>
	</div>
<script type="text/javascript">
	var products = document.getElementsByClassName('box');
	for (var i = 0; i < products.length; i++) {
		new Draggable(products[i].id, {ghosting:true, revert:true})	
	}
	Droppables.add('cart', {onDrop:addProduct})
</script>	
</body>
</html>
Code:
<?php
session_start();
function stringForJavascript($in_string) {
   $str = ereg_replace("[\r\n]", " \\n\\\n", $in_string);
   $str = ereg_replace('"', '\\"', $str);
   Return $str;
}
if (isset($_GET['clearProduct'])) {
	$_SESSION['cart'][$_GET['id']]--;
	if ($_SESSION['cart'][$_GET['id']] == 0) {
		unset($_SESSION['cart'][$_GET['id']]);	
	}
	foreach ($_SESSION['cart'] as $key => $value) {
		print "$key = $value <span style=\"color:blue; text-decoration:underline; cursor:pointer\" onclick=\"clearProduct('$key');\">DELETE</span><br />";
	}
	sleep(1);
	die;
}
if (isset($_GET['clear'])) {
	unset($_SESSION['cart']);
	sleep(1);
	die;
}
$prodid = $_GET['product_id'];
$_SESSION['cart'][$prodid] = 1 + $_SESSION['cart'][$prodid];
foreach ($_SESSION['cart'] as $key => $value) {
	print "$key = $value <span style=\"color:blue; text-decoration:underline; cursor:pointer\" onclick=\"clearProduct('$key');\">DELETE</span><br />";
}
sleep(1);
?>
jibber4568 is offline   Reply With Quote
Sponsored Links
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
KonaKart v2.2.4.0 Free Java Shopping Cart microbee AJAX Help 0 03-20-2008 12:11 AM
XML shopping cart sexshop365 XML and XSLT 1 06-13-2007 01:05 PM
Ajax Workshop 3: Shopping Cart using Script.aculo.us Ajaxking AJAX Articles 0 01-03-2007 05:38 AM


All times are GMT -4. The time now is 12:06 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0
Copyright ©2006 - 2009, AJAXwith.com