added params ajax option to pass extra params to transport. fixes #492
This commit is contained in:
parent
d56f43092b
commit
2f53c251d4
18
select2.js
18
select2.js
@ -317,30 +317,38 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
data = options.data, // ajax data function
|
data = options.data, // ajax data function
|
||||||
url = options.url, // ajax url string or function
|
url = options.url, // ajax url string or function
|
||||||
transport = options.transport || $.ajax,
|
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;
|
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;
|
url = (typeof url === 'function') ? url.call(this, query.term, query.page, query.context) : url;
|
||||||
|
|
||||||
if( null !== handler) { handler.abort(); }
|
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,
|
url: url,
|
||||||
dataType: options.dataType,
|
dataType: options.dataType,
|
||||||
data: data,
|
data: data,
|
||||||
type: type,
|
type: type,
|
||||||
cache: false,
|
cache: false,
|
||||||
traditional: traditional,
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (requestNumber < requestSequence) {
|
if (requestNumber < requestSequence) {
|
||||||
return;
|
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);
|
var results = options.results(data, query.page);
|
||||||
query.callback(results);
|
query.callback(results);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
handler = transport.call(null, params);
|
||||||
}, quietMillis);
|
}, quietMillis);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user