代码之家  ›  专栏  ›  技术社区  ›  Todd Smith Brandon

从jquery ajax response html更新多个div

  •  3
  • Todd Smith Brandon  · 技术社区  · 15 年前

    我在ASP.NET MVC购物车中有一个页面,允许您输入优惠券并显示订单摘要以及其他页面内容。我想要一个更新按钮,它将验证优惠券代码,报告任何错误,并通过jquery ajax更新页面上的订单摘要。

    我知道我可以通过创建一个表单和局部视图来实现这一点,并在jquery submit中使用target属性。但是,我想我可以做如下的事情:

    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来做到这一点?

    4 回复  |  直到 15 年前