我在一個asp.net mvc購物車中有一個頁面,它允許您輸入優惠券並顯示訂單摘要以及其他頁面內容。我想要一個更新按鈕,它將驗證優惠券代碼,報告任何錯誤,並通過jQuery ajax更新頁面上的訂單摘要。從jQuery ajax響應中更新多個div html
我知道我可以做一個表單和部分視圖,並使用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做到這一點?
這是一個代碼小寶石 - 非常感謝你:] – xgstr 2013-08-22 09:19:13