$(selector)中的jQuery Uncaught TypeError .on() [英] jQuery Uncaught TypeError in $(selector).on()

查看:102
本文介绍了$(selector)中的jQuery Uncaught TypeError .on()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

Uncaught TypeError: ((jQuery.event.special[handleObj.origType] || (intermediate value)).handle || handleObj.handler).apply is not a function

这是我的代码,它位于 beforeSend success 之间,发生错误:

This is my code and it's somewhere in between the beforeSend and the success calls that the error is happening:

$('#main-container').on('click', '#sign-in-btn', function (event) {
    var username = $('#username-textbox').val();
    var password = $('#password-textbox').val();

    $.ajax({
        url: '/login',
        method: 'POST',

        beforeSend: function (xhr) {
            xhr.setRequestHeader('Authorization', 'Basic ' + btoa(username + ":" + password));
        },

        success: function (data) {
        }
    });

    event.preventDefault();
});

我还试图放入 $(文件).ready(函数) (){...} 调用,我得到完全相同的错误。

I also tried to put inside a $(document).ready(function () { ... } call and I get the exact same error.

推荐答案

拥有事件函数返回 false 修复它,因为错误发生在事件传播期间,如果事件返​​回 false 那么 event.stopPropagation()被调用。

Having the event function return false fixed it because the error was somewhere during the propagation of the event and if an event returns false then event.stopPropagation() is "called".

这篇关于$(selector)中的jQuery Uncaught TypeError .on()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆