Skip to content

Instantly share code, notes, and snippets.

@objectivehtml
Created November 8, 2012 21:21
Show Gist options
  • Select an option

  • Save objectivehtml/4041705 to your computer and use it in GitHub Desktop.

Select an option

Save objectivehtml/4041705 to your computer and use it in GitHub Desktop.
jQuery(document).ready(function($){
// this will set JSON as the return data type, and identify update_cart as a callback function
var cart_form_options = {
success: update_cart, // post-submit callback
dataType: 'json'
};
// this is the callback script. whenever a form is updated, this script will be called
function update_cart(data, statusText, xhr, $form) {
// "data" is the returned data in json format
// you can access each of these using data.item_name as shown in the example below
if (data.success) {
// update the XID hash in the form so we don't run afoul of EE's secure forms
$("input[name=XID]").val(data.XID);
// using the json data object's data to update various totals. in this case
$('.cart_tax') .html( data.cart_tax );
$('.cart_total') .html( data.cart_total );
$('.cart_shipping') .html( data.cart_shipping );
$('.cart_subtotal') .html( data.cart_subtotal );
$('.cart_discount') .html( data.cart_discount );
}
return true;
}
// finding the form that contains this input
var form = $(this).closest("form");
// initialize the form
$(form).ajaxForm(cart_form_options);
// submit the form.
$(form).submit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment