We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,220 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

jQuery Ajax Add to Cart Problem

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

3
Contributors
2
Replies
3 Months
Discussion Span
9 Months Ago
Last Updated
3
Views
simplypixie
Practically a Master Poster
642 posts since Oct 2010
Reputation Points: 157
Solved Threads: 118
Skill Endorsements: 5

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

pritaeas
Posting Prodigy
Moderator
9,304 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,463
Skill Endorsements: 86

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.

simplypixie
Practically a Master Poster
642 posts since Oct 2010
Reputation Points: 157
Solved Threads: 118
Skill Endorsements: 5

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0684 seconds using 2.71MB