I've attached an onlcick event to a form's submit button to override the default POST request, but I'm having some trouble getting it to work.
What I want is for the item clicked to add to the shopping cart, but only show a modal confirmation and not refresh the page.
This code was working in my static example but something I've done since integrating it has made it break.
function cartSubmit(addbtn)
{
var form = addbtn.parentNode.parentNode.parentNode;
var formData = jQuery(form).serializeArray();
jQuery.post("/myurl/", formData, function(r){
jQuery.colorbox({html:'<div style="padding:10px;"><h2>Product added to cart.</h2></div>'});
});
return false;
}
Now I get an error in console saying POST "http://localhost/myurl/" undefined (undefined) then the form submits normally (refreshes the page), but seems also to submit with the javascript because it adds the item to the cart twice.
Anyway, any help is greatly appreciated!