简体   繁体   中英

jQuery Uncaught TypeError in $(selector).on()

I am getting the following error:

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

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();
});

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

让事件函数返回false修复它,因为错误是在事件传播期间的某处,如果事件返​​回falseevent.stopPropagation()被“调用”。

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