Created
November 8, 2012 21:21
-
-
Save objectivehtml/4041705 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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