Browse Source

Added a check for the `results` key in AJAX responses

This should prevent users from running into unexpected errors when
they do not return an object with the `results` key containing an
array.

This closes https://github.com/select2/select2/issues/2950.
Kevin Brown 10 years ago
parent
commit
5b4e1eab42

+ 10 - 0
dist/js/select2.amd.full.js

@@ -2626,6 +2626,16 @@ define('select2/data/ajax',[
       $request.success(function (data) {
         var results = self.processResults(data, params);
 
+        if (console && console.error) {
+          // Check to make sure that the response included a `results` key.
+          if (!results || !results.results || !$.isArray(results.results)) {
+            console.error(
+              'Select2: The AJAX results did not return an array in the ' +
+              '`results` key of the response.'
+            );
+          }
+        }
+
         callback(results);
       });
 

+ 10 - 0
dist/js/select2.amd.js

@@ -2626,6 +2626,16 @@ define('select2/data/ajax',[
       $request.success(function (data) {
         var results = self.processResults(data, params);
 
+        if (console && console.error) {
+          // Check to make sure that the response included a `results` key.
+          if (!results || !results.results || !$.isArray(results.results)) {
+            console.error(
+              'Select2: The AJAX results did not return an array in the ' +
+              '`results` key of the response.'
+            );
+          }
+        }
+
         callback(results);
       });
 

+ 10 - 0
dist/js/select2.full.js

@@ -12161,6 +12161,16 @@ define('select2/data/ajax',[
       $request.success(function (data) {
         var results = self.processResults(data, params);
 
+        if (console && console.error) {
+          // Check to make sure that the response included a `results` key.
+          if (!results || !results.results || !$.isArray(results.results)) {
+            console.error(
+              'Select2: The AJAX results did not return an array in the ' +
+              '`results` key of the response.'
+            );
+          }
+        }
+
         callback(results);
       });
 

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.full.min.js


+ 10 - 0
dist/js/select2.js

@@ -3054,6 +3054,16 @@ define('select2/data/ajax',[
       $request.success(function (data) {
         var results = self.processResults(data, params);
 
+        if (console && console.error) {
+          // Check to make sure that the response included a `results` key.
+          if (!results || !results.results || !$.isArray(results.results)) {
+            console.error(
+              'Select2: The AJAX results did not return an array in the ' +
+              '`results` key of the response.'
+            );
+          }
+        }
+
         callback(results);
       });
 

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.min.js


+ 10 - 0
src/js/select2/data/ajax.js

@@ -46,6 +46,16 @@ define([
       $request.success(function (data) {
         var results = self.processResults(data, params);
 
+        if (console && console.error) {
+          // Check to make sure that the response included a `results` key.
+          if (!results || !results.results || !$.isArray(results.results)) {
+            console.error(
+              'Select2: The AJAX results did not return an array in the ' +
+              '`results` key of the response.'
+            );
+          }
+        }
+
         callback(results);
       });
 

Some files were not shown because too many files changed in this diff