@@ -443,6 +443,16 @@ the specific language governing permissions and limitations under the Apache Lic
443443 // TODO - replace query.page with query so users have access to term, page, etc.
444444 // added query as third paramter to keep backwards compatibility
445445 var results = options . results ( data , query . page , query ) ;
446+ query . callback ( results ) ;
447+ } ,
448+ error : function ( jqXHR , textStatus , errorThrown ) {
449+ var results = {
450+ hasError : true ,
451+ jqXHR : jqXHR ,
452+ textStatus : textStatus ,
453+ errorThrown : errorThrown ,
454+ } ;
455+
446456 query . callback ( results ) ;
447457 }
448458 } ) ;
@@ -1766,6 +1776,12 @@ the specific language governing permissions and limitations under the Apache Lic
17661776 return ;
17671777 }
17681778
1779+ // handle ajax error
1780+ if ( data . hasError !== undefined && checkFormatter ( opts . formatAjaxError , "formatAjaxError" ) ) {
1781+ render ( "<li class='select2-ajax-error'>" + evaluate ( opts . formatAjaxError , opts . element , data . jqXHR , data . textStatus , data . errorThrown ) + "</li>" ) ;
1782+ return ;
1783+ }
1784+
17691785 // save context, if any
17701786 this . context = ( data . context === undefined ) ? null : data . context ;
17711787 // create a default choice and prepend it to the list
@@ -3408,6 +3424,7 @@ the specific language governing permissions and limitations under the Apache Lic
34083424 formatSelectionCssClass : function ( data , container ) { return undefined ; } ,
34093425 formatMatches : function ( matches ) { if ( matches === 1 ) { return "One result is available, press enter to select it." ; } return matches + " results are available, use up and down arrow keys to navigate." ; } ,
34103426 formatNoMatches : function ( ) { return "No matches found" ; } ,
3427+ formatAjaxError : function ( jqXHR , textStatus , errorThrown ) { return "Loading failed" ; } ,
34113428 formatInputTooShort : function ( input , min ) { var n = min - input . length ; return "Please enter " + n + " or more character" + ( n == 1 ? "" : "s" ) ; } ,
34123429 formatInputTooLong : function ( input , max ) { var n = input . length - max ; return "Please delete " + n + " character" + ( n == 1 ? "" : "s" ) ; } ,
34133430 formatSelectionTooBig : function ( limit ) { return "You can only select " + limit + " item" + ( limit == 1 ? "" : "s" ) ; } ,
0 commit comments