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" />

The jQery/Ajax is:

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

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

        url: '/inc/shopping_bag_functions.php',
        data: $(this).serialize() + '&action=add',
        type: 'POST',
        success: function(html) {
            $('#shopping-bag p').html(html);
                    height: 100,
            if(currentUrl == '/shopping-bag.php') {
                $('.add-item').fadeOut(1000, function() {
                $("#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

Recommended Answers

All 2 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.