Search code examples
jquery-select2-4jquery-select2

select2 (remote data) throws exception because of typing to fast


I'm using select2 for loading remote data. I declared the minimumInputLength to 3 letters, so after that it will start searching. Whenever I hit the fourth letter while typing fast I get an Javascript exception saying :

Sorry. An error occured while communicating with the server. Please try again later.

How can I avoid this? I already changed the quietMillis (waitTimesMs) to lower or higher (does this even have something to do with it?).

Every help is appreciate.

My code is like:

$(function () { $("#Search").select2({ minimumInputLength: 3, ajax: { url: site, dataType: "json", quietMillis: waitTimeMs, data: function (params) { var page = (params.page || 1) - 1; return { searchText: params.term, pageCount: 10, page: page }; }, processResults: function (data) { var select2Data = $.map(data.Items, function (obj) { obj.id = obj.ID; obj.text = obj.Name; return obj; }); return { results: select2Data, pagination: { more: (data.PageNo * 10) < data.TotalCount } }; }


Solution

  • Finally it works! select2 changed "quietMillis" to "delay" so I could change quietMillis as big as I wanted and nothing changed at all...