From 70be25cc6df96fa1b36d789192e48ab0f487729e Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Tue, 19 Feb 2013 13:21:57 -0800 Subject: [PATCH] fix ajax url() context. fixes #895 --- select2.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/select2.js b/select2.js index 400f8ff4..12edbf7f 100644 --- a/select2.js +++ b/select2.js @@ -341,7 +341,8 @@ the specific language governing permissions and limitations under the Apache Lic requestSequence = 0, // sequence used to drop out-of-order responses handler = null, quietMillis = options.quietMillis || 100, - ajaxUrl = options.url; + ajaxUrl = options.url, + self = this; return function (query) { window.clearTimeout(timeout); @@ -354,14 +355,14 @@ the specific language governing permissions and limitations under the Apache Lic 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; + data = data ? data.call(self.opts.element, query.term, query.page, query.context) : null; + url = (typeof url === 'function') ? url.call(self.opts.element, query.term, query.page, query.context) : url; if( null !== handler) { handler.abort(); } if (options.params) { if ($.isFunction(options.params)) { - $.extend(params, options.params.call(null)); + $.extend(params, options.params.call(self.opts.element)); } else { $.extend(params, options.params); } @@ -382,7 +383,7 @@ the specific language governing permissions and limitations under the Apache Lic query.callback(results); } }); - handler = transport.call(null, params); + handler = transport.call(self.opts.element, params); }, quietMillis); }; }