简体   繁体   中英

jQuery trigger does not execute custom event

I am trying to subscribe an html element within a page to events. Once such an event is triggered, the html element should display error information to the user. These error triggers will be triggered within AJAX call error functions. However, once such an error happens, the customer event is never triggered. Here is the code for the html observer:

$(function(){
  $('#errorNotification').on('/nofitications/error', function(event, message){
    console.log('event triggered');
    var errorElement = $('#errorNotification');
    var errorTitle = $('#errorNotification #title');
    var errorMessage = $('#errorNotification #message');
    $(errorElement).addClass('alert-error');
    errorTitle.html(message.title);
    errorMessage.html(message.content);
  });
});

And here is the code from the AJAX call that should trigger the event:

.finally(function () {
     $('#errorNotification').trigger('/notifications/error', {title: 'Fehler', content: 'content'});
 });

Even though the finally function does get executed after the AJAX call finishes, the custom event is never executed.

Any pointers will be highly appreciated.

错字:第2行第一个代码段: $('#errorNotification').on('/nofitications/error' ...应该是noTiFications而不是nofitications

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM