From c8b274e9abec3ed825c91b517c3124bb62a31fad Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Wed, 11 Apr 2012 12:17:58 -0700 Subject: [PATCH] added ajax.transport variable to provide a custom transport. closes #26 --- select2.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/select2.js b/select2.js index 4dce400c..cc4ab536 100755 --- a/select2.js +++ b/select2.js @@ -190,9 +190,10 @@ * Produces an ajax-based query function * * @param options object containing configuration paramters - * @param options.ajax url for the data + * @param options.transport function that will be used to execute the ajax request. must be compatible with parameters supported by $.ajax + * @param options.url url for the data * @param options.data a function(searchTerm, pageNumber) that should return an object containing query string parameters for the above url. - * @param options.dataType request data type: ajax, jsonp, other datatatypes supported by jQuery's $.ajax function + * @param options.dataType request data type: ajax, jsonp, other datatatypes supported by jQuery's $.ajax function or the transport function if specified * @param options.quietMillis (optional) milliseconds to wait before making the ajaxRequest, helps debounce the ajax function if invoked too often * @param options.results a function(remoteData, pageNumber) that converts data returned form the remote request to the format expected by Select2. * The expected format is an object containing the following keys: @@ -210,11 +211,12 @@ timeout = window.setTimeout(function () { requestSequence += 1; // increment the sequence var requestNumber = requestSequence, // this request's sequence number - data = options.data; // ajax data function + data = options.data, // ajax data function + transport=options.transport||$.ajax; data = data.call(this, query.term, query.page); - $.ajax({ + transport.call(null, { url: options.url, dataType: options.dataType, data: data,