Select2: ajax results could not be loaded.

Created on 14 Apr 2016  路  3Comments  路  Source: select2/select2

I using select2 version 4 using ajax for my option. whenever i try to do some searching, select2 will show 'The results could not be loaded'.
a
b

$( "#thisid" ).select2({        
    minimumInputLength: 2,
    ajax: {
      url: "search-product.php",
      dataType: 'json',
      data: function (params) {
            return {
                q: params.term // search term
            };
        },
        processResults: function (data) {
            // parse the results into the format expected by Select2.
            // since we are using custom formatting functions we do not need to
            // alter the remote JSON data
            return {
                results: data
            };
        },
        cache: true
    },
    minimumInputLength: 2
});

Environment

Browsers

  • [ ] Google Chrome
  • [x] Mozilla Firefox
  • [ ] Internet Explorer

Operating System

  • [x] Windows
  • [ ] Mac OS X
  • [ ] Linux
  • [ ] Mobile

Most helpful comment

in processResult using

var newData = []; for (var i = 0; i < data.length; i++) { newData.push({ id: data[i].ID, //id part present in data text: data[i].Nome //string to be displayed }); } return { results: newData };

All 3 comments

This appears to be more of a usage question than a bug report or common feature request. As we continue to keep the Select2 issue tracker geared towards these two areas, bug reports and common feature requests, we are redirecting usage questions to other communities such as the mailing list, IRC, or Stack Overflow.

in processResult using

var newData = []; for (var i = 0; i < data.length; i++) { newData.push({ id: data[i].ID, //id part present in data text: data[i].Nome //string to be displayed }); } return { results: newData };

@cesguto it's just no change

Was this page helpful?
0 / 5 - 0 ratings