From 5a831afb9a7d46e8f20aec21164cfbfd182024de Mon Sep 17 00:00:00 2001
From: Kevin Brown
Date: Sat, 23 Apr 2016 22:23:04 -0400
Subject: [PATCH] Added documentation for ajax.url
This closes https://github.com/select2/select2/issues/4213.
---
docs/_includes/options/data/ajax.html | 38 +++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/docs/_includes/options/data/ajax.html b/docs/_includes/options/data/ajax.html
index bfd677f1..77472741 100644
--- a/docs/_includes/options/data/ajax.html
+++ b/docs/_includes/options/data/ajax.html
@@ -63,6 +63,36 @@ $('select').select2({
This will tell Select2 to wait 250 milliseconds before sending the request out to your API.
+
+ How do I tell Select2 which URL to get the results from?
+
+
+
+ When connecting Select2 to a remote data source, you have the option of using either a single endpoint (a single page which handles all requests) or a dynamic endpoint (one of many pages). You can point Select2 to a single endpoint during initialization by specifying a string for the ajax.url
option.
+
+
+{% highlight js linenos %}
+$('select').select2({
+ ajax: {
+ url: '/path/to/search/endpoint'
+ }
+});
+{% endhighlight %}
+
+
+ If there isn't a single url for your search results, or you need to call a function to determine the url to use, you can specify a function for the ajax.url
option, and this will be used instead. The query parameters will be passed in through the params
option.
+
+
+{% highlight js linenos %}
+$('select').select2({
+ ajax: {
+ url: function (params) {
+ return '/some/url/' + params.term;
+ }
+ }
+});
+{% endhighlight %}
+
I want to add more query parameters to the request, where can this be done?
@@ -87,6 +117,14 @@ $('select').select2({
});
{% endhighlight %}
+
+ The results that I am seeing never change
+
+
+
+ Select2 expects that the results that are returned from the remote endpoint are already filtered ahead of time based on the search term. If your remote endpoint just returns the list of all possible options, you may be interested in using Select2's support for data arrays.
+
+
Can an AJAX plugin other than jQuery.ajax
be used?