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
Related Article: Textarea validation problem jquery
is a solved JavaScript / DHTML / AJAX discussion thread by Albert Pinto that has 3 replies and was last updated 2 months ago.
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
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