Enabling jQuery Autocomplete on dynamically created input fields

前端 未结 5 1061
鱼传尺愫
鱼传尺愫 2021-01-05 15:23

I\'ve read almost every article i could find on how to accomplish this, but i\'m still failing miserably. mostly because i\'m an amateur at jQuery/Javascript.

I have

5条回答
  •  被撕碎了的回忆
    2021-01-05 15:37

    Here is the simpler way to use autocomplete for dynamically created input fields.

    $('body').on('focus', '.dynamic-input-class', function (e) {
     $(this).autocomplete({
      minLength: 2,
      delay: 500,
      source: function (request, response) {
       $.ajax( {
          url: "server side path that returns json data",
          data: { searchText: request.term},
          type: "POST",
          dataType: "json",
          success: function( data ) {
            $("#data-success").html(data.returnedData); //returnedData is json data return from server side response
          }
        });
      }
     });
    });
    

提交回复
热议问题