1
0
mirror of synced 2024-11-26 14:56:07 +03:00

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.
This commit is contained in:
Kevin Brown 2015-01-21 16:36:23 -05:00
parent 850816ee77
commit 5b4e1eab42
7 changed files with 54 additions and 4 deletions

View File

@ -2626,6 +2626,16 @@ define('select2/data/ajax',[
$request.success(function (data) { $request.success(function (data) {
var results = self.processResults(data, params); 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); callback(results);
}); });

View File

@ -2626,6 +2626,16 @@ define('select2/data/ajax',[
$request.success(function (data) { $request.success(function (data) {
var results = self.processResults(data, params); 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); callback(results);
}); });

View File

@ -12161,6 +12161,16 @@ define('select2/data/ajax',[
$request.success(function (data) { $request.success(function (data) {
var results = self.processResults(data, params); 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); callback(results);
}); });

File diff suppressed because one or more lines are too long

10
dist/js/select2.js vendored
View File

@ -3054,6 +3054,16 @@ define('select2/data/ajax',[
$request.success(function (data) { $request.success(function (data) {
var results = self.processResults(data, params); 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); callback(results);
}); });

File diff suppressed because one or more lines are too long

View File

@ -46,6 +46,16 @@ define([
$request.success(function (data) { $request.success(function (data) {
var results = self.processResults(data, params); 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); callback(results);
}); });