Ricky
Ricky

Reputation: 3072

Bootstrap Notify Duplicate Notifications After Consequent AJAX Calls

I'm using the most recent release of Bootstrap Notify (v3.1.5) to show status messages after an AJAX call. It works as expected in the first call. After the first execution, every time the notify is called, its shows the previous notifications message.

Example:

1st call = 1 Notify message; 2nd call = 2 Notify messages; 3rd call = 3 Notify messages; ...

Bootstrap Notify Initialisation:

$.notify({
    icon: icon,
    title: title,
    message: message
}, {
    type: type,
    allow_dismiss: true,
    newest_on_top: false,
    placement: {
        from: "top",
        align: "right"
    },
    offset: 20,
    spacing: 10,
    z_index: 100000,
    delay: delay,
    timer: 1000,
    mouse_over: true,
    animate: {
        enter: 'animated fadeInDown',
        exit: 'animated fadeOutUp'
    }
});

How can i solve this issue?

Upvotes: 1

Views: 1718

Answers (2)

Lovekesh Kumar Singh
Lovekesh Kumar Singh

Reputation: 11

you can prevent by using get all notifications length and prevent it. if notify greater than 0 return false;

let notifylength = document.querySelectorAll('.bootstrap-notify-container');
if(notifylength.length !== 0){
    return false;
}

Upvotes: 1

Ricky
Ricky

Reputation: 3072

Solved my issue. After some debugging i realized that the event was being triggered multiple times and that cause the notifications to pop up repeatedly. Really big rookie mistake...

Upvotes: 1

Related Questions