使用select2
$("#select").select2({
ajax: {
url: "/getcity",
dataType: 'json',
type: 'post',
delay: 250,
allowClear: false,
minimumInputLength: 3,
cache: true
}
});每次我集中注意力的时候,它都会发出请求,而不是平面语,只是url。因此,如果在以前的好请求中,我收到了良好的数据,那么它将显示在select中,在下一个焦点上,select2发出空请求并在select中清除数据。如何预防?
发布于 2016-04-05 10:30:19
您应该将minimumInputLength和其他一些选项移到ajax之外,因为它们不是ajax的选项。在您的示例中,select2从未获得minimumInputLength选项,每次得到焦点时都会调用ajax。
$("#select").select2({
ajax: {
url: "/getcity",
dataType: 'json',
type: 'post',
delay: 250,
cache: true
},
allowClear: false,
minimumInputLength: 3
});https://stackoverflow.com/questions/36423704
复制相似问题