简体   繁体   English

jQuery触发器不执行自定义事件

[英]jQuery trigger does not execute custom event

I am trying to subscribe an html element within a page to events. 我正在尝试将页面中的html元素订阅到事件。 Once such an event is triggered, the html element should display error information to the user. 触发此类事件后,html元素应向用户显示错误信息。 These error triggers will be triggered within AJAX call error functions. 这些错误触发器将在AJAX调用错误函数中触发。 However, once such an error happens, the customer event is never triggered. 但是,一旦发生此类错误,就永远不会触发客户事件。 Here is the code for the html observer: 这是html观察者的代码:

$(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: 这是应该触发事件的AJAX调用中的代码:

.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. 即使AJAX调用完成后finally函数确实得到执行,自定义事件也永远不会执行。

Any pointers will be highly appreciated. 任何指针将不胜感激。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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