agarzola / jQueryAutocompletePlugin

Jörn Zaefferer’s (now deprecated) jQuery plugin, with tweaks.
282 stars 151 forks source link

Default options class #21

Open foglcz opened 13 years ago

foglcz commented 13 years ago

Hi, when using the plugin with default ajax handlers, the request might not go through (actually, not call the plugin's success function.) The cause was when I called something like this elsewhere in the scripts:

jQuery.ajaxSetup({
    success: myGenericHandler,
    dataType: "json"
});

Then, none of the requests would call the succes handler of autocomplete, therefore, not displaying the results.

Fix is on line 23, modify the default options class:


options = $.extend({}, $.Autocompleter.defaults, {
    url: isUrl ? urlOrData : null,
    data: isUrl ? null : urlOrData,
    delay: isUrl ? $.Autocompleter.defaults.delay : 10,
    max: options && !options.scroll ? 10 : 150,
    dataType : isUrl ? 'html' : null
}, options);

-> simply set the datatype.

The "datatype" parameter is used within the rest of the class, but there's no default value for it. Adding this line will fix the problem with issue above.

Klap-in commented 12 years ago

It is only used for ajax requests, thus adding this to the $.Autocompleter.defaults is fine, isn't it?

$.Autocompleter.defaults = {
    ...
    dataType: 'html',
    ...
}