weixin_33737774 2018-01-30 15:17 采纳率: 0%
浏览 364

select2延迟不起作用

I am using below code to initialise select2 on a select box. But the delay is not working, requests are going to server immediately.

$(".multi_select").select2({
    multiple: true,
    allowClear: true,
    minimumInputLength: 2,
    delay: 5000,
    ajax: {
      url: "/search.json",
      dataType: 'json'
    }
  });

Another problem I am facing is, I am getting abort error on fast typing, that means previous requests are not getting aborted. Yesterday when I added above code, without delay, it was working fine without 'abort' error. Today, it gives abort error, with and without delay along with failure of delay.

I am using v4.0.3 and there is no change in project since yesterday so I don't understand that what happened suddenly.

  • 写回答

1条回答 默认 最新

  • derek5. 2018-01-31 11:08
    关注

    The delay parameter has to be added to ajax section:

    $(".multi_select").select2({
        multiple: true,
        allowClear: true,
        minimumInputLength: 2,
        ajax: {
          url: "/search.json",
          dataType: 'json',
          delay: 5000
        }
    });
    

    See: https://select2.org/data-sources/ajax#rate-limiting-requests

    评论

报告相同问题?