简体   繁体   English

如果包含ajax,则回调失败

[英]Callback failing if contains ajax

I'm trying to add a callback to a pre existing function in the jquery plugin nitelite https://github.com/premasagar/nitelite - The callback works fine http://jsfiddle.net/HPc4e/2/ - unless I have ajax in the callback? 我试图将回调添加到jquery插件nitelite中的现有功能中https://github.com/premasagar/nitelite-回调工作正常http://jsfiddle.net/HPc4e/2/-除非我有回调中的ajax?

Appropriate section of close function: 关闭功能的适当部分:

// Blah blah ...

else {

    showFlash();

    this.overlay.remove();

    this.container
        .empty()
        .remove();

    $(this).triggerHandler('close');

    // Add callback
    if (typeof callback == "function") {
        callback();
    }

}
return this;

Callback: 打回来:

lb.close(undefined, 'click', function() {
    $.ajax({
        type: 'POST',
        url: url,
        data: {submit: $(this).val()},
        dataType: 'json',
        success: function(data) {
            lightbox('Lightbox 2', '<p>Oh hi</p>', 'lightbox2');
        }
    });
});

Thanks 谢谢

I suspect that your callback is throwing an exception. 我怀疑您的回调引发了异常。

What is the value of this supposed to be when it's invoked? 什么是价值this设想时,它调用呢? Are you sure it's pointing at a jQuery compatible element that has a .val() method? 您确定它指向具有.val()方法的jQuery兼容元素吗?

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

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