diff --git a/select2.css b/select2.css index df8b9fcc..e43fd401 100644 --- a/select2.css +++ b/select2.css @@ -422,9 +422,9 @@ html[dir="rtl"] .select2-results { color: #000; } - .select2-results .select2-no-results, .select2-results .select2-searching, +.select2-results .select2-ajax-error, .select2-results .select2-selection-limit { background: #f4f4f4; display: list-item; @@ -454,6 +454,10 @@ disabled look for disabled choices in the results dropdown background: #f4f4f4 url('select2-spinner.gif') no-repeat 100%; } +.select2-results .select2-ajax-error { + background: rgba(255, 50, 50, .2); +} + .select2-more-results { background: #f4f4f4; display: list-item; diff --git a/select2.js b/select2.js index 7a425e8e..25d12b0d 100644 --- a/select2.js +++ b/select2.js @@ -443,6 +443,16 @@ the specific language governing permissions and limitations under the Apache Lic // TODO - replace query.page with query so users have access to term, page, etc. // added query as third paramter to keep backwards compatibility var results = options.results(data, query.page, query); + query.callback(results); + }, + error: function(jqXHR, textStatus, errorThrown){ + var results = { + hasError: true, + jqXHR: jqXHR, + textStatus: textStatus, + errorThrown: errorThrown, + }; + query.callback(results); } }); @@ -1766,6 +1776,12 @@ the specific language governing permissions and limitations under the Apache Lic return; } + // handle ajax error + if(data.hasError !== undefined && checkFormatter(opts.formatAjaxError, "formatAjaxError")) { + render("