How to reload the page after the message closes using Hubspot Messenger(). run()?

Asked

Viewed 51 times

5

I’m making an MVC app and I need to re-load after the message closes (success or not). How can I do this?

Codepen for testing: http://codepen.io/larissa/pen/rjOpRM/

HTML:

<button class="btn btn-danger deleteButton" id="btnAction" data-url="https://jsonplaceholder.typicode.com/posts/1">
  Click me
</button>

Javascript:

$(function () {
    //Messenger options
    Messenger.options = {
        extraClasses: 'messenger-fixed messenger-on-bottom',
        theme: 'flat',
        messageDefaults: {
            showCloseButton: true,
            scrollTo: true
        }
    };

    $(document).on('click', 'button.deleteButton', function (e) {
        Messenger().run({
            successMessage: 'Registro removido com sucesso!',
            errorMessage: 'Error',
            progressMessage: 'Removendo registro...',
            events: {
                "click": function () {
                    window.location.reload();
                    alert("Reload!");
                }
            }
        }, {
            method: 'DELETE',
            url: $(this).data('url'),
            error: function (jqXHR, textStatus, errorThrown) {
                return errorThrown;
            }
        });
    });
});

1 answer

2


I decided to change the way I was making the call ajax. For me, it worked beauty!

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

    Messenger().run({
        successMessage: 'Registro removido com sucesso!',
        progressMessage: 'Removendo registro...'
    }, {
        method: 'DELETE',
        url: urlDelete,
        error: function (jqXHR, textStatus, errorThrown) {
             return errorThrown;
        },
        complete: function () {
            table.ajax.reload();
        }
    });
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.