I have a page in a asp.net mvc shopping cart which allows you to enter a coupon and shows an order summary along with other page content. I would like to have an Update button which will validate the coupon code, report any errors and also update the order summary on the page via jQuery ajax.
I know I could do this by making a form and partial view and use the target property in the jQuery submit. However, was thinking I could do something like the following:
var options
{
success: function (responseHtml) // contains the entire form in the response
{
// extract sub-sections from responseHtml and update accordingly
// update <div id="coupon"> with coupon div from responseHtml
// update <div id="order-summary> with order summary div from responseHtml
}
}
$('#my-form').ajaxSubmit(options); // submits the entire form
The advantage here is that I wouldn't have to do a full page refresh or create a partial view containing all of the areas that need updating. Is there an appropriate way to do this via jQuery ajax?