Hey there,
So I have this problem.
I'm making an AJAX cart for a website I'm working on.
My code is semi-functional. It gets the information correctly (Name, price, etc.), but it requests it twice so it adds it twice. So if I click on 'add to cart,' it will add it twice.
I think I know the problem but I can't really figure the solution out. Haven't worked a lot with AJAX to be honest.
This is my cart:
Onclick, both this:
And this:
Gets updated, but like I said, unfortunately, it gets updated twice.
Here is the code for the top text:
Here is my code for the content inside the dropdown / white part:
I believe it's getting added twice because I have
data: $('#product :input'),
in both codes, but I have no idea what else I can put to only grab the content and not submit it or whatever.
Help?
So I have this problem.
I'm making an AJAX cart for a website I'm working on.
My code is semi-functional. It gets the information correctly (Name, price, etc.), but it requests it twice so it adds it twice. So if I click on 'add to cart,' it will add it twice.
I think I know the problem but I can't really figure the solution out. Haven't worked a lot with AJAX to be honest.
This is my cart:
Onclick, both this:
And this:
Gets updated, but like I said, unfortunately, it gets updated twice.
Here is the code for the top text:
Code:
<script type="text/javascript"><!--
$(document).ready(function () {
$('#add_to_cart').removeAttr('onclick');
$('#add_to_cart').click(function () {
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/minicart',
dataType: 'html',
data: $('#product :input'),
success: function (html) {
$('#textamountexel').html(html);
}
});
});
});
</script>
Here is my code for the content inside the dropdown / white part:
Code:
<script type="text/javascript"><!--
$(document).ready(function () {
$('#add_to_cart').removeAttr('onclick');
$('#add_to_cart').click(function () {
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
dataType: 'html',
data: $('#product :input'),
success: function (html) {
$('#exelcartbody').html(html);
},
complete: function () {
var image = $('#image').offset();
var cart = $('#exelcartbody').offset();
$('#image').before('<img src="' + $('#image').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
params = {
top : cart.top + 'px',
left : cart.left + 'px',
opacity : 0.0,
width : $('#exelcartbody').width(),
heigth : $('#exelcartbody').height()
};
$('#temp').animate(params, 'slow', false, function () {
$('#temp').remove();
});
}
});
});
});
//--></script>
I believe it's getting added twice because I have
data: $('#product :input'),
in both codes, but I have no idea what else I can put to only grab the content and not submit it or whatever.
Help?