diff --git a/readme.md b/readme.md index 83821e9..f9f4900 100644 --- a/readme.md +++ b/readme.md @@ -37,6 +37,7 @@ The standard jquery.autocomplete.js file is around 2.7KB when minified via Closu * `transformResult`: `function(response) {}` called after the result of the query is ready. Converts the result into response.suggestions format. * `autoSelectFirst`: if set to `true`, first item will be selected when showing suggestions. Default value `false`. * `appendTo`: container where suggestions will be appended. Default value `body`. Can be jQuery object, selector or html element. Make sure to set `position: absolute` or `position: relative` for that element. + * `dataType`: type of data returned from server. Either 'text' (default) or 'jsonp', which will cause the autocomplete to use jsonp. You may return a json object in your callback when using jsonp. ##Usage diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index 4b422e3..8708c1c 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -89,6 +89,7 @@ onSearchComplete: noop, containerClass: 'autocomplete-suggestions', tabDisabled: false, + dataType : 'text', lookupFilter: function (suggestion, originalQuery, queryLowerCase) { return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1; }, @@ -406,7 +407,7 @@ url: options.serviceUrl, data: options.params, type: options.type, - dataType: 'text' + dataType: options.dataType }).done(function (txt) { that.processResponse(txt); options.onSearchComplete.call(that.element, q); @@ -476,7 +477,7 @@ processResponse: function (text) { var that = this, - response = $.parseJSON(text); + response = typeof text == 'string' ? $.parseJSON(text) : text; response.suggestions = that.verifySuggestionsFormat(that.options.transformResult(response));