Skip to content

Commit 13c1dcb

Browse files
committed
add default ajax options. fixes select2#1125
1 parent 694432d commit 13c1dcb

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

select2.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,11 @@ the specific language governing permissions and limitations under the Apache Lic
359359
* Produces an ajax-based query function
360360
*
361361
* @param options object containing configuration paramters
362+
* @param options.params parameter map for the transport ajax call, can contain such options as cache, jsonpCallback, etc. see $.ajax
362363
* @param options.transport function that will be used to execute the ajax request. must be compatible with parameters supported by $.ajax
363364
* @param options.url url for the data
364365
* @param options.data a function(searchTerm, pageNumber, context) that should return an object containing query string parameters for the above url.
365366
* @param options.dataType request data type: ajax, jsonp, other datatatypes supported by jQuery's $.ajax function or the transport function if specified
366-
* @param options.cache set to true to disable jquery's cache-busting url parameters
367-
* @param options.jsonpCallback set to override the jquery callback function - useful in conjunction with options.cache
368-
* @param options.traditional a boolean flag that should be true if you wish to use the traditional style of param serialization for the ajax request
369367
* @param options.quietMillis (optional) milliseconds to wait before making the ajaxRequest, helps debounce the ajax function if invoked too often
370368
* @param options.results a function(remoteData, pageNumber) that converts data returned form the remote request to the format expected by Select2.
371369
* The expected format is an object containing the following keys:
@@ -388,11 +386,15 @@ the specific language governing permissions and limitations under the Apache Lic
388386
var requestNumber = requestSequence, // this request's sequence number
389387
data = options.data, // ajax data function
390388
url = ajaxUrl, // ajax url string or function
391-
transport = options.transport || $.ajax,
392-
cache = options.cache || false,
393-
jsonpCallback = options.jsonpCallback || undefined,
394-
type = options.type || 'GET', // set type of request (GET or POST)
395-
params = {};
389+
transport = options.transport || $.fn.select2.defaults.ajax.transport,
390+
// deprecated - to be removed in 4.0 - use params instead
391+
deprecated = {
392+
type: options.type || 'GET', // set type of request (GET or POST)
393+
cache: options.cache || false,
394+
jsonpCallback: options.jsonpCallback||undefined,
395+
dataType: options.dataType||"json"
396+
},
397+
params = $.extend({}, $.fn.select2.defaults.ajax.params, deprecated);
396398

397399
data = data ? data.call(self, query.term, query.page, query.context) : null;
398400
url = (typeof url === 'function') ? url.call(self, query.term, query.page, query.context) : url;
@@ -411,9 +413,6 @@ the specific language governing permissions and limitations under the Apache Lic
411413
url: url,
412414
dataType: options.dataType,
413415
data: data,
414-
type: type,
415-
cache: cache,
416-
jsonpCallback: jsonpCallback,
417416
success: function (data) {
418417
if (requestNumber < requestSequence) {
419418
return;
@@ -3001,6 +3000,14 @@ the specific language governing permissions and limitations under the Apache Lic
30013000
return replace_map[match];
30023001
});
30033002
},
3003+
ajax: {
3004+
transport: $.ajax,
3005+
params: {
3006+
type: "GET",
3007+
cache: false,
3008+
dataType: "json"
3009+
}
3010+
},
30043011
blurOnChange: false,
30053012
selectOnBlur: false,
30063013
adaptContainerCssClass: function(c) { return c; },

0 commit comments

Comments
 (0)