0

I am using jQuery and Ajax to add items to a shopping cart and in all areas of the site apart from one it works fine and I cannot for the life of me work out why this one area isn't working.

The form code (which is the same as in all other Add To Cart forms) is:

<form method="" class="add_to_cart">  
    <input type="hidden" name="item_id" value="prods_<?php echo $prodid;?>" />
    <input type="hidden" name="unit_price" value="<?php echo $price;?>" />
    <input type="hidden" name="item_name" value="<?php echo $objproducts->prod_name.' - '.$objproducts->prod_code;?>" />
    <input type="hidden" name="image" value="/images/products_tb/<?php echo $objproducts->prod_img; ?>" />
    <input type="hidden" name="item_qty" value="1"/>
    <input type="hidden" name="item_url" value="/diesel_engine_products/<?php echo $catid; ?>/<?php echo $objproducts->prodid; ?>/"/>
    <input type="submit" class="rounded-buttons" name="add_to_bag" value="Add to Bag" />
</form>

The jQery/Ajax is:

$('.add_to_cart').submit(function (e) {
    e.preventDefault();

    var currentUrl = window.location.href.substr(window.location.href.lastIndexOf("/") + 1);;

    $.ajax({
        url: '/inc/shopping_bag_functions.php',
        data: $(this).serialize() + '&action=add',
        type: 'POST',
        success: function(html) {
            $('#shopping-bag p').html(html);
            $('.add-item')
                .fadeIn('fast')
                .dialog({
                    height: 100,
                    modal:true
                });
            if(currentUrl == '/shopping-bag.php') {
                $('.add-item').fadeOut(1000, function() {
                  $(".add-item").dialog('close');
                });
                $("#inner-content").load(location.href + " #inner-content>*", "");
            }
        }
    });
});

The page where this is not working on the site is when viewing individual products, for example This Page.

Can anyone see the problem as I can't and am fairly sure it is something simply

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by simplypixie
0

Correct me if I'm wrong, but I can't find your js code on that page. Looks like your scripts are not included.

Edited by pritaeas: Edit

0

It might be loading the old site as the image in my first post is a cached one. The scripts are definitely included. I use the same page to load multiple products and they add to the cart, it is just when only one products is displayed.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.