Reputation: 58
using select2
$("#select").select2({
ajax: {
url: "/getcity",
dataType: 'json',
type: 'post',
delay: 250,
allowClear: false,
minimumInputLength: 3,
cache: true
}
});
Eevery time i focus it makes request with no params, just url. So if in previous good request i've received good data, it shows in select, on next focus select2 make empty request and clear data in select. How prevent it?
Upvotes: 0
Views: 462
Reputation: 8482
You should move minimumInputLength
and some other options outside of ajax
because they are not ajax
's options. In your case select2 never gets the option minimumInputLength
and does ajax calls everytime when it gets focus.
$("#select").select2({
ajax: {
url: "/getcity",
dataType: 'json',
type: 'post',
delay: 250,
cache: true
},
allowClear: false,
minimumInputLength: 3
});
Upvotes: 1