How to reload window after Hubspot Messenger().run() message closes?

189 views Asked by At

I'm writing an MVC app and I really need a reload window after message (both error and success) closes. How can I achieve this?

Actually, I'm trying this code on my button click, but no luck:

    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 to test: http://codepen.io/larissa/pen/rjOpRM/

2

There are 2 answers

3
Lari On BEST ANSWER

I decide to change approach to this solution. Thanks to @codenut for the help! Using this code, works for me.

$(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();
        }
    });
});
5
codenut On

Not sure but try this

   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();
         },

    });