From 0fa338409c74078c936bb77e27ad454df1417605 Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Sun, 28 Feb 2016 12:53:57 -0500 Subject: [PATCH] Fixes #3653, refactors several lines to use expectsJSON --- RELEASE-NOTES.md | 3 ++- src/definitions/behaviors/api.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 78c45157f..dbff38cea 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -17,7 +17,8 @@ -**Divider** - Fixed issue where descenders like "g" would be cut off in `horizontal divider` #3585 **Bugs** -**Grid** - Fixed issue where `centered` content would cause `justified` content to appear aligned left. #3496 +- **API** - Fixed bug where using `onResponse` with `dataType` other than JSON or JSONP would cause an error. (Not allowing plain text responses to be translated) #3653 +- **Grid** - Fixed issue where `centered` content would cause `justified` content to appear aligned left. #3496 - **Button** - Fixes issue where `right icon` like `right arrow icon` would have additional margin inside an `icon button` #3525 - **Checkbox** - Fixed a chrome issue where radio buttons may receive `indeterminate` styles when user has not yet interacted with the page - **Dropdown** - Fixed issue where `apiSettings` was not defaulting to use `cache: 'local'` as specified in the docs diff --git a/src/definitions/behaviors/api.js b/src/definitions/behaviors/api.js index b02f7f402..30e686643 100644 --- a/src/definitions/behaviors/api.js +++ b/src/definitions/behaviors/api.js @@ -275,6 +275,9 @@ $.api = $.fn.api = function(parameters) { disabled: function() { return ($module.filter(selector.disabled).length > 0); }, + expectingJSON: function() { + return settings.dataType !== 'json' && settings.dataType !== 'jsonp'; + }, form: function() { return $module.is('form') || $context.is('form'); }, @@ -298,7 +301,7 @@ $.api = $.fn.api = function(parameters) { } }, validResponse: function(response) { - if( (settings.dataType !== 'json' && settings.dataType !== 'jsonp') || !$.isFunction(settings.successTest) ) { + if( (!module.is.expectingJSON()) || !$.isFunction(settings.successTest) ) { module.verbose('Response is not JSON, skipping validation', settings.successTest, response); return true; } @@ -468,7 +471,9 @@ $.api = $.fn.api = function(parameters) { elapsedTime = (new Date().getTime() - requestStartTime), timeLeft = (settings.loadingDuration - elapsedTime), translatedResponse = ( $.isFunction(settings.onResponse) ) - ? settings.onResponse.call(context, $.extend(true, {}, response)) + ? module.is.expectingJSON() + ? settings.onResponse.call(context, $.extend(true, {}, response)) + : settings.onResponse.call(conetxt, response) : false ; timeLeft = (timeLeft > 0) @@ -677,7 +682,7 @@ $.api = $.fn.api = function(parameters) { get: { responseFromXHR: function(xhr) { return $.isPlainObject(xhr) - ? (settings.dataType == 'json' || settings.dataType == 'jsonp') + ? (module.is.expectingJSON()) ? module.decode.json(xhr.responseText) : xhr.responseText : false