繁体   English   中英

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

[英]jQuery trigger does not execute custom event

我正在尝试将页面中的html元素订阅到事件。 触发此类事件后,html元素应向用户显示错误信息。 这些错误触发器将在AJAX调用错误函数中触发。 但是,一旦发生此类错误,就永远不会触发客户事件。 这是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);
  });
});

这是应该触发事件的AJAX调用中的代码:

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

即使AJAX调用完成后finally函数确实得到执行,自定义事件也永远不会执行。

任何指针将不胜感激。

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

暂无
暂无

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

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