未捕获的TypeError:无法读取未定义的属性“更改”

时间:2014-11-07 08:23:02

标签: javascript jquery ajax jquery-chosen

此错误背后的原因是什么?

最新的jquery版本2.1.1中是否弃用change属性?

我目前正在使用ajax选择的库,其功能如下所示:

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

我通过链接找到了这个:https://rvieiraweb.wordpress.com/2013/04/20/jquery-ajax-chosen-simple-demo-tutorial/

有人遇到同样的问题吗?

1 个答案:

答案 0 :(得分:2)

似乎ajaxChosen()不返回相同的对象。 尝试将事件处理程序直接附加到jquery对象

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