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

10,596

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

Share:
10,596
David Gomes
Author by

David Gomes

Software Engineer who is really interested in UX. Graduated in Software Engineering in Portugal. Currently @memsql, previously @Unbabel.

Updated on June 05, 2022

Comments

  • David Gomes
    David Gomes almost 2 years

    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.

    • ozil
      ozil over 8 years
      you have to include jquery before and put it in $( document ).ready(function() {...});
    • Artem Baranovskii
      Artem Baranovskii over 8 years
      Try to use Pause on exception feature in Chrome Dev Tools and go through call stack up with exploring variables
    • VisioN
      VisioN over 8 years
      @ozil Even the first line won't be executed if jQuery was not included or ready wrapper was not implemented.
    • David Gomes
      David Gomes over 8 years
      I wrapped it inside a $(document).ready() call and I still get the exact same error. Editing the question to include that.