使用select2
$("#select").select2({
ajax: {
url: "/getcity",
dataType: 'json',
type: 'post',
delay: 250,
allowClear: false,
minimumInputLength: 3,
cache: true
}
});
我每次关注时都会提出没有参数的请求,只是网址。因此,如果在先前的良好请求中我已经收到了良好的数据,则它会在选择中显示,在下一个焦点上选择2,在select中发出空请求和清除数据。如何防止它?
答案 0 :(得分:1)
您应该在minimumInputLength
之外移动ajax
和其他一些选项,因为它们不是ajax
选项。在你的情况下,select2永远不会得到选项minimumInputLength
,并且每次获得焦点时都会调用ajax。
$("#select").select2({
ajax: {
url: "/getcity",
dataType: 'json',
type: 'post',
delay: 250,
cache: true
},
allowClear: false,
minimumInputLength: 3
});