materialize-autocomplete icon indicating copy to clipboard operation
materialize-autocomplete copied to clipboard

get data ajax call

Open pooyagolchian opened this issue 7 years ago • 1 comments

var resultCache = $.ajax({
        url: 'http://contact.dev/api/autocomplete/person_tags',
        type: 'GET',
        success: function (data) {
            personTags = data;
            var multiple = $('#person_tags').materialize_autocomplete({
                multiple: {
                    enable: true
                },
                appender: {
                    el: '.ac-users'
                },
                dropdown: {
                    el: '#multipleDropdown'
                }
            });
            resultCache = personTags;
            console.log(resultCache);
            multiple.resultCache = resultCache;


        },
        error: function (xhr, resp, text) {
            console.log(xhr, resp, text);
        }

    });

please help! How to use getData option for ajax call.

pooyagolchian avatar May 24 '17 13:05 pooyagolchian

You can use $.get()...

    $('#my_autocomplete').materialize_autocomplete({
      multiple: {
        enable: false
      },
      dropdown: {
        itemTemplate: '<li class="ac-item" data-id="<%= item.id %>" data-text="<%= item.text %>"><a href="javascript:void(0)"><%= item.text %></a></li>',
        noItem: "No matching items"
      },
      hidden: {
        enable: false
      },
      onSelect: function (item) {
        // ... do something here if you chose ...
      },
      getData: function (value, callback) {
        $.get("/path/to/server/autocomplete/results", { term: value })
          .success(function(data) {
            callback(value, data);
          })
      }
    });

kiere avatar Jun 27 '17 03:06 kiere