View Full Version : Javascript/Ajax Help please

04-13-2010, 08:17 PM
I have a shopping cart and I am adding two items to it at once using the code below.

If you click under the wall art section all the way through and select 'add to cart' it only adds one item to the cart. If you hit the browsers back button and try it again, the code works and both items are added to the cart.

Any ideas why this is happening?

<script type="text/javascript"><!--
$('.add-items').live('click', function(evt) {
if (evt.button != 0) return; // ignore right-click

var items = $(this).attr('href').substr(1).split(',');
// now items is ['G400191', 'G410003']

// Disable the link to prevent repeated orders

// Execute the orders using ajax
var remaining_requests_cnt = items.length;
for (var i = 0; i < items.length; i++) {
url: '/cgi/cart.cgi?'+items[i],
success: function() {
if (--remaining_requests_cnt == 0) {
error: function() {
alert('Error occurred. Check the content of your cart.');

<div class="framePrice">
<div align="left" style="width:auto; height:auto; margin:auto; font-family:Arial, Helvetica, sans-serif; font-weight:bold; color:#666;">
<p>Silver Frame<br />
Astronomy 400191<br />
<div align="left" style="width:auto; height:auto; margin:auto;"></div>
<div align="left" style="width:auto; height:auto; margin:auto;"></div>
<div align="left" style="width:auto; height:auto; margin:auto; margin-top:10px;">
<a href="#G400191,G410003" class="add-items"><img src="images/cart.png" alt="add to cart" width="71" height="26" border="0" /></a>