【问题标题】:Select2 not working - No results foundSelect2 不工作 - 未找到结果
【发布时间】:2017-11-10 14:15:12
【问题描述】:

我正在使用 Select2 并不断得到“未找到结果”,即使我的 JSON 数组获取结果。有什么想法吗?否则选择框工作正常。

<script>
$(document).ready(function() {
  $('#supplier').select2({
  ajax: {
  url: 'lagraGet.php',
  data: function (params) {
     var query = {
         search: params.term,
         type: 'GET',
         what: 'suppliers'
      }
      return query;
   }
  }
 });
});
</script>

JSON 响应:

{"results":[{"id":1,"text":"Studio 27 HB"}],"pagination":{"more":false}}

【问题讨论】:

    标签: javascript json jquery-select2


    【解决方案1】:

    我在数据类型中找到了答案。我补充说: dataType: 'json', 到 ajax 列表中,它工作正常。

    $('#supplier').select2({
     ajax: {
      url: 'lagraGet.php',
      dataType: json,
      data: function (params) {
         var query = {
             search: params.term,
             type: 'GET',
             what: 'suppliers'
          }
          return query;
       }
      }
     });
    

    【讨论】:

      猜你喜欢
      • 2017-11-12
      • 2016-10-30
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 2020-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多