Skip to content

Commit 3757add

Browse files
author
Tomas Kirda
committed
Merge pull request devbridge#36 from jesseditson/master
Added JSONP support (via new dataType option)
2 parents a64be99 + f1f104d commit 3757add

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ The standard jquery.autocomplete.js file is around 2.7KB when minified via Closu
3737
* `transformResult`: `function(response) {}` called after the result of the query is ready. Converts the result into response.suggestions format.
3838
* `autoSelectFirst`: if set to `true`, first item will be selected when showing suggestions. Default value `false`.
3939
* `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.
40+
* `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.
4041

4142
##Usage
4243

src/jquery.autocomplete.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
onSearchComplete: noop,
9090
containerClass: 'autocomplete-suggestions',
9191
tabDisabled: false,
92+
dataType : 'text',
9293
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
9394
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
9495
},
@@ -406,7 +407,7 @@
406407
url: options.serviceUrl,
407408
data: options.params,
408409
type: options.type,
409-
dataType: 'text'
410+
dataType: options.dataType
410411
}).done(function (txt) {
411412
that.processResponse(txt);
412413
options.onSearchComplete.call(that.element, q);
@@ -476,7 +477,7 @@
476477

477478
processResponse: function (text) {
478479
var that = this,
479-
response = $.parseJSON(text);
480+
response = typeof text == 'string' ? $.parseJSON(text) : text;
480481

481482
response.suggestions = that.verifySuggestionsFormat(that.options.transformResult(response));
482483

0 commit comments

Comments
 (0)