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

做~自己de王妃 提交于 2019-12-19 09:27:06

问题


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.


回答1:


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".



来源:https://stackoverflow.com/questions/31876769/jquery-uncaught-typeerror-in-selector-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!