From c68358c875f2452ba6cbe045e870a317041483b8 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 26 Jul 2013 12:02:28 -0700 Subject: [PATCH] CRM-13121 - CRM.api - Always encode data with JSON The query-string encoder misencodes empty arrays -- and most likely misencodes other things. ---------------------------------------- * CRM-13121: CRM.api cannot call "replace" with empty list http://issues.civicrm.org/jira/browse/CRM-13121 --- js/rest.js | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/js/rest.js b/js/rest.js index f784d890a1..f88e60f6ed 100644 --- a/js/rest.js +++ b/js/rest.js @@ -86,8 +86,7 @@ var CRM = CRM || {}; */ CRM.api = function(entity, action, params, options) { // Default settings - var json = false, - settings = { + var settings = { context: null, success: function(result, settings) { return true; @@ -102,7 +101,7 @@ var CRM = CRM || {}; } return settings.success.call(this, result, settings); }, - ajaxURL: 'civicrm/ajax/rest', + ajaxURL: 'civicrm/ajax/rest' }; action = action.toLowerCase(); // Default success handler @@ -122,24 +121,11 @@ var CRM = CRM || {}; return true; }; } - for (var i in params) { - if (i.slice(0, 4) == 'api.' || typeof(params[i]) == 'Object') { - json = true; - break; - } - } - if (json) { - params = { - entity: entity, - action: action, - json: JSON.stringify(params) - }; - } - else { - params.entity = entity; - params.action = action; - params.json = 1; - } + params = { + entity: entity, + action: action, + json: JSON.stringify(params) + }; // Pass copy of settings into closure to preserve its value during multiple requests (function(stg) { $.ajax({ -- 2.25.1