2017-01-09 19 views
0

我寫了一個MVC應用程序,並且在消息(錯誤和成功)都關閉後,我確實需要重新加載窗口。 我該如何做到這一點?如何在Hubspot Messenger()。run()消息關閉後重新加載窗口?

其實,我想在我的按鈕點擊這個代碼,但沒有運氣:

Messenger().run({ 
     successMessage: 'Record Removed!', 
     errorMessage: 'Error', 
     progressMessage: 'Removing record...', 
     events: { 
      "click": function() { 
       window.location.reload(); 
      } 
     } 
    }, { 
     method: 'DELETE', 
     url: $(this).data('url'), 
     error: function (jqXHR, textStatus, errorThrown) { 
      return errorThrown; 
     } 
    }); 

CodePen測試:http://codepen.io/larissa/pen/rjOpRM/

回答

0

我決定改變這種解決方案。感謝@codenut的幫助! 使用此代碼,適合我。

$(document).on('click', 'button.deleteButton', function (e) { 
    var urlDelete = $(this).data('url'); 
    var table = $('#' + $(this).data('grid')).DataTable(); 

    Messenger().run({ 
     successMessage: 'Row removed!', 
     progressMessage: 'Removing row...' 
    }, { 
     method: 'DELETE', 
     url: urlDelete, 
     error: function (jqXHR, textStatus, errorThrown) { 
      return errorThrown; 
     }, 
     complete: function() { 
      table.ajax.reload(); 
     } 
    }); 
}); 
+1

不錯,但是如何在錯誤時重新加載。並且我已經中和了你的問題;) – codenut

+0

@codenut,用這種方法,我做了部分重新加載,只對受刪除操作影響的網格。您的幫助對這個解決方案至關重要! – Lari

+1

很高興聽到這個消息 – codenut

1

不知道,但嘗試這個

Messenger().run({ 
     successMessage: 'Record Removed!', 
     errorMessage: 'Error', 
     progressMessage: 'Removing record...', 
     events: { 
      "click": function() { 
       window.location.reload(); 
      } 
     } 
    }, { 
     method: 'DELETE', 
     url: $(this).data('url'), 
     error: function (data) { 
       location.reload(); 
     }, 
     success: function (data) { 
       location.reload(); 
     }, 

    }); 
+0

謝謝@codenut,但是使用這種方法,在** ajax執行之前會發生**重載。 – Lari

+0

現在更新代碼。 – codenut

+0

再次感謝@codenut,採用這種新方法,萬一發生錯誤,MVC返回的特定消息不會顯示出來。 – Lari

相關問題