Uncaught TypeError: Cannot read property 'change' of undefined

What is the reason for this error?

Is the property change

deprecated in the latest jQuery 2.1.1?

I am currently working on a selected ajax library where the function looks like below:

       $(document).ready(function () {
          $("#jacComplete").ajaxChosen({
             type: 'GET',
             url: '/Movies/GetMoviesStartsWith',
             dataType: 'json'
          }, 
          function (data) {
             var terms = {};

             $.each(data, function (i, val) {
                terms[i] = val;
             });

             return terms;
          }).change(function () { 
             //you can see the IDs in console off all items in autocomplete and deal with them
             console.log($("#jacComplete").val());
          });
       });

      

I found this from the link: https://rvieiraweb.wordpress.com/2013/04/20/jquery-ajax-chosen-simple-demo-tutorial/

Has anyone faced the same problem?

+3


source to share


1 answer


It seems ajaxChosen () is not returning the same object. Try attaching your event handler directly to the jquery object



$(document).ready(function () {
  $("#jacComplete").ajaxChosen({
     type: 'GET',
     url: '/Movies/GetMoviesStartsWith',
     dataType: 'json'
  }, 
  function (data) {
     var terms = {};
     $.each(data, function (i, val) {
        terms[i] = val;
     });
     return terms;
  });
  $("#jacComplete").change(function () { 
     //you can see the IDs in console off all items in autocomplete and deal with them
     console.log($("#jacComplete").val());
  });
});

      

+2


source







All Articles