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

5

I'm doing an MVC app and need to do a reload after the message close (successful or not). How can I do this?

CodePen for testing: link

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;
            }
        });
    });
});
    
asked by anonymous 09.01.2017 / 18:05

1 answer

2

I decided to change the way I was doing the so-called 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();
        }
    });
});
    
10.01.2017 / 01:17