Error: cannot call methods on autocomplete prior t

2019-02-21 22:51发布

问题:

I am using ajax-solr. It works fine with jquery-ui-1.8.*.

But when I upgrade it to jquery-1.10.* it gives me this exception:

cannot call methods on autocomplete prior to initialization; attempted to call method 'destroy'

回答1:

I got the answer to it in the initialization of autocomplete widget...just add

$(this.target).find('input').autocomplete();

This will initialize the autocomplete widget this happened because in 1.10.* .Jquery has added error messages for usage of functions without proper initialization whereas it was not there in previous versions.



回答2:

If you want to make sure the autocomplete widget is destroyed, you can check if it was actually initialized by inspecting the CSS classes of the target element, e.g.

if ($target.hasClass('ui-autocomplete')) {
    $target.autocomplete('destroy')
}