From 2f53c251d451d75b1572ca2cc61aecf2c92b5eae Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Sat, 9 Feb 2013 01:20:19 -0800 Subject: [PATCH] added params ajax option to pass extra params to transport. fixes #492 --- select2.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/select2.js b/select2.js index e2fd91e7..79ca9179 100644 --- a/select2.js +++ b/select2.js @@ -317,30 +317,38 @@ the specific language governing permissions and limitations under the Apache Lic data = options.data, // ajax data function url = options.url, // ajax url string or function transport = options.transport || $.ajax, - traditional = options.traditional || false, - type = options.type || 'GET'; // set type of request (GET or POST) + type = options.type || 'GET', // set type of request (GET or POST) + params = {}; data = data ? data.call(this, query.term, query.page, query.context) : null; url = (typeof url === 'function') ? url.call(this, query.term, query.page, query.context) : url; if( null !== handler) { handler.abort(); } - handler = transport.call(null, { + if (options.params) { + if ($.isFunction(options.params)) { + $.extend(params, options.params.call(null)); + } else { + $.extend(params, options.params); + } + } + + $.extend(params, { url: url, dataType: options.dataType, data: data, type: type, cache: false, - traditional: traditional, success: function (data) { if (requestNumber < requestSequence) { return; } - // TODO 3.0 - replace query.page with query so users have access to term, page, etc. + // TODO - replace query.page with query so users have access to term, page, etc. var results = options.results(data, query.page); query.callback(results); } }); + handler = transport.call(null, params); }, quietMillis); }; }