【发布时间】:2009-06-08 04:07:57
【问题描述】:
我在 asp.net mvc 购物车中有一个页面,它允许您输入优惠券并显示订单摘要以及其他页面内容。我想要一个更新按钮,它将验证优惠券代码,报告任何错误并通过 jQuery ajax 更新页面上的订单摘要。
我知道我可以通过制作表单和局部视图并在 jQuery 提交中使用目标属性来做到这一点。但是,我认为我可以执行以下操作:
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
这里的优点是我不必进行整页刷新或创建包含所有需要更新的区域的局部视图。有没有合适的方法通过 jQuery ajax 做到这一点?
【问题讨论】:
标签: jquery asp.net-mvc ajax