Ensure headers are set correctly for json output
authorColeman Watts <coleman@civicrm.org>
Mon, 25 Aug 2014 21:44:21 +0000 (22:44 +0100)
committerColeman Watts <coleman@civicrm.org>
Mon, 25 Aug 2014 21:44:21 +0000 (22:44 +0100)
22 files changed:
CRM/Activity/Page/AJAX.php
CRM/Admin/Page/AJAX.php
CRM/Badge/Page/AJAX.php
CRM/Campaign/Page/AJAX.php
CRM/Case/Page/AJAX.php
CRM/Contact/Form/Inline.php
CRM/Contact/Page/AJAX.php
CRM/Core/IDS.php
CRM/Core/Page/AJAX.php
CRM/Core/Page/AJAX/Location.php
CRM/Core/QuickForm/Action/Display.php
CRM/Event/Page/AJAX.php
CRM/Financial/Page/AJAX.php
CRM/Group/Page/AJAX.php
CRM/Mailing/Page/AJAX.php
CRM/Member/Page/AJAX.php
CRM/Queue/ErrorPolicy.php
CRM/Queue/Page/AJAX.php
CRM/UF/Page/AJAX.php
CRM/UF/Page/ProfileEditor.php
CRM/Utils/JSON.php
CRM/Utils/REST.php

index 2f8faaca95bd515afb0d6feeb4382565adf25a70..2c6f56b9c0745c1015fad4f7d0bfad023bf37d25 100644 (file)
@@ -296,14 +296,12 @@ class CRM_Activity_Page_AJAX {
 
   static function convertToCaseActivity() {
     $params = array('caseID', 'activityID', 'contactID', 'newSubject', 'targetContactIds', 'mode');
+    $vals = array();
     foreach ($params as $param) {
       $vals[$param] = CRM_Utils_Array::value($param, $_POST);
     }
 
-    $retval = self::_convertToCaseActivity($vals);
-
-    echo json_encode($retval);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output(self::_convertToCaseActivity($vals));
   }
 
   /**
index ebc458f0b31e1a0fcb776c099d13470699383968..7df95e15ff44423dacb5cf0e5c5e25edf09862ff 100644 (file)
@@ -292,8 +292,7 @@ LIMIT $limit";
       }
       $result[] = $row;
     }
-    print json_encode($result);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($result);
   }
 
   function mappingList() {
@@ -303,8 +302,7 @@ LIMIT $limit";
     }
 
     if (!$mappingID) {
-      echo json_encode(array('error_msg' => 'required params missing.'));
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output(array('error_msg' => 'required params missing.'));
     }
 
     $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection1($mappingID);
@@ -318,8 +316,7 @@ LIMIT $limit";
       );
     }
 
-    echo json_encode($elements);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($elements);
   }
 
   function mappingList1() {
@@ -329,8 +326,7 @@ LIMIT $limit";
     }
 
     if (!$mappingID) {
-      echo json_encode(array('error_msg' => 'required params missing.'));
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output(array('error_msg' => 'required params missing.'));
     }
 
     $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection1($mappingID);
@@ -345,8 +341,7 @@ LIMIT $limit";
     }
     $elements['recipientMapping'] = $recipientMapping;
 
-    echo json_encode($elements);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($elements);
   }
 
   static function mergeTags() {
@@ -367,8 +362,7 @@ LIMIT $limit";
       array(1 => $result['tagA'], 2 => $result['tagB'])
     );
 
-    echo json_encode($result);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($result);
   }
 
   function recipient() {
@@ -378,8 +372,7 @@ LIMIT $limit";
     }
 
     if (!$recipient) {
-      echo json_encode(array('error_msg' => 'required params missing.'));
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output(array('error_msg' => 'required params missing.'));
     }
 
     switch ($recipient) {
@@ -403,8 +396,7 @@ LIMIT $limit";
       );
     }
 
-    echo json_encode($elements);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($elements);
   }
 }
 
index 424f34786a912fc7967592d74aada9a3a648b4af..604c2588bbcca44754a1f09f1066a6c598f6d675 100644 (file)
@@ -36,7 +36,6 @@ class CRM_Badge_Page_AJAX {
   static function getImageProp() {
     $img = $_GET['img'];
    list($w, $h) = CRM_Badge_BAO_Badge::getImageProperties($img);
-    echo json_encode(array('width' => $w, 'height' => $h));
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output(array('width' => $w, 'height' => $h));
   }
-}
\ No newline at end of file
+}
index d998914852fac6a945e17e44b4086937eb46de6c..3512bc1c4d74316d11bb60aec81a9600cf8440c9 100644 (file)
@@ -92,8 +92,7 @@ class CRM_Campaign_Page_AJAX {
     $errors = CRM_Core_BAO_CustomField::validateCustomData($params);
     if (is_array($errors) && !empty($errors)) {
       $result['errors'] = $errors;
-      echo json_encode($result);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($result);
     }
 
     //process the response/interview data.
@@ -102,9 +101,7 @@ class CRM_Campaign_Page_AJAX {
       $result['status'] = 'success';
     }
 
-    echo json_encode($result);
-
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($result);
   }
 
   static function loadOptionGroupDetails() {
@@ -144,8 +141,7 @@ class CRM_Campaign_Page_AJAX {
       'result' => $opValues,
     );
 
-    echo json_encode($result);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($result);
   }
 
   function voterList() {
@@ -480,8 +476,7 @@ class CRM_Campaign_Page_AJAX {
       }
     }
 
-    echo json_encode(array('status' => $status));
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output(array('status' => $status));
   }
 
   function allActiveCampaigns() {
@@ -512,9 +507,7 @@ class CRM_Campaign_Page_AJAX {
       'campaigns' => $options,
     );
 
-    echo json_encode($results);
-
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($results);
   }
 
   function campaignGroups() {
@@ -549,9 +542,7 @@ class CRM_Campaign_Page_AJAX {
       'groups' => $groups,
     );
 
-    echo json_encode($results);
-
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($results);
   }
 
   /**
index c5033fdd46772cb8b58f9eb28dcbfd8612a30db7..6b83546414d4b73338a8dbdd547f706a2f0194fc 100644 (file)
@@ -61,8 +61,7 @@ class CRM_Case_Page_AJAX {
         'extra' => $details,
       );
     }
-    print json_encode($results);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($results);
   }
 
   function processCaseTags() {
@@ -182,8 +181,7 @@ class CRM_Case_Page_AJAX {
     );
 
     CRM_Case_BAO_Case::processCaseActivity($caseParams);
-    echo json_encode(TRUE);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output(TRUE);
   }
 
   /**
index 77c6e02d50d24fcca38f82a8699e45ea7179b991..ee3d17dfe9c2e6791cf55242597b6fa5fa548bcf 100644 (file)
@@ -107,8 +107,7 @@ abstract class CRM_Contact_Form_Inline extends CRM_Core_Form {
    */
   public function cancelAction() {
     $response = array('status' => 'cancel');
-    echo json_encode($response);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($response);
   }
 
   /**
index f26e4acbf8cacd5cfd643c9499a91ddde736c907..8473a71c0103b095d9f203fdb308a4ffbf45c67e 100644 (file)
@@ -242,8 +242,7 @@ class CRM_Contact_Page_AJAX {
     while ($dao->fetch()) {
       $results[] = array('id' => $dao->id, 'text' => $dao->data);
     }
-    print json_encode($results);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($results);
   }
 
   static function relationship() {
@@ -305,8 +304,7 @@ class CRM_Contact_Page_AJAX {
       }
     }
 
-    echo json_encode($ret);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($ret);
   }
 
   /**
@@ -319,8 +317,7 @@ class CRM_Contact_Page_AJAX {
     $values           = array();
 
     CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $values, $returnProperties);
-    echo json_encode($values);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($values);
   }
 
   static function groupTree() {
@@ -570,8 +567,7 @@ ORDER BY sort_name ";
           CRM_Utils_Hook::enableDisable($recordBAO, $recordID, $isActive);
         }
       }
-      echo json_encode($status);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($status);
     }
   }
 
@@ -800,8 +796,7 @@ LIMIT {$offset}, {$rowCount}
 
     $subTypes = CRM_Contact_BAO_ContactType::subTypePairs($contactType, FALSE, NULL);
     asort($subTypes);
-    echo json_encode($subTypes);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($subTypes);
   }
 
   static function buildDedupeRules() {
@@ -823,8 +818,7 @@ LIMIT {$offset}, {$rowCount}
 
     $dedupeRules = CRM_Dedupe_BAO_RuleGroup::getByType($contactType);
 
-    echo json_encode($dedupeRules);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($dedupeRules);
   }
 
   /**
@@ -856,8 +850,7 @@ LIMIT {$offset}, {$rowCount}
         CRM_Utils_System::civiExit();
     }
 
-    echo json_encode($dashlets);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($dashlets);
   }
 
   /**
@@ -876,8 +869,7 @@ LIMIT {$offset}, {$rowCount}
       );
     }
 
-    echo json_encode($signatures);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($signatures);
   }
 
   /**
@@ -910,8 +902,7 @@ LIMIT {$offset}, {$rowCount}
       $status = $exception->delete();
     }
 
-    echo json_encode(array('status' => ($status) ? $oper : $status));
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output(array('status' => ($status) ? $oper : $status));
   }
 
   static function getDedupes() {
@@ -973,8 +964,7 @@ LIMIT {$offset}, {$rowCount}
 
     $pdfFormat = CRM_Core_BAO_PdfFormat::getById($formatId);
 
-    echo json_encode($pdfFormat);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($pdfFormat);
   }
 
   /**
@@ -985,8 +975,7 @@ LIMIT {$offset}, {$rowCount}
 
     $paperSize = CRM_Core_BAO_PaperSize::getByName($paperSizeName);
 
-    echo json_encode($paperSize);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($paperSize);
   }
 
   static function selectUnselectContacts() {
@@ -1020,8 +1009,7 @@ LIMIT {$offset}, {$rowCount}
     $countSelectionCids = count($contactIds[$cacheKey]);
 
     $arrRet = array('getCount' => $countSelectionCids);
-    echo json_encode($arrRet);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($arrRet);
   }
 
   /**
@@ -1050,8 +1038,7 @@ LIMIT {$offset}, {$rowCount}
       $addressVal = CRM_Core_BAO_Address::getValues($entityBlock);
     }
 
-    echo json_encode($addressVal);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($addressVal);
   }
 
   /**
index a6e68cf2f88ede0704fe202fcbc62360c2f9c277..c6055cf9d804c9df355153ad8870f1bae974f0bf 100644 (file)
@@ -275,8 +275,7 @@ class CRM_Core_IDS {
           'reason' => 'XSS suspected',
         )
       );
-      echo json_encode($error);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($error);
     }
     CRM_Core_Error::fatal($msg);
   }
index 593beb5f3cc3a4569db118827e07f68e6f77cfb3..42ac838b464a0b572bc82c469e682f4d3b5f021f 100644 (file)
@@ -126,9 +126,7 @@ class CRM_Core_Page_AJAX {
     if (!$result) {
       $priceSetId = null;
     }
-    echo json_encode($priceSetId);
-
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($priceSetId);
   }
 
   /**
index d4e126ae97c15c027a2349aa0c4f6112f86e267c..90e553da6313a7a30e9097868cd2b9c985d679f3 100644 (file)
@@ -195,8 +195,7 @@ class CRM_Core_Page_AJAX_Location {
         }
       }
 
-    echo json_encode($elements);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($elements);
   }
 
   static function jqState() {
@@ -259,7 +258,6 @@ class CRM_Core_Page_AJAX_Location {
     // set the message if loc block is being used by more than one event.
     $result['count_loc_used'] = CRM_Event_BAO_Event::countEventsUsingLocBlockId($_POST['lbid']);
 
-    echo json_encode($result);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($result);
   }
 }
index f7d20fcf029787003d9321aaccdf10e529fa83c2..d785e34c6319270e30a31259e86748606e9fc504 100644 (file)
@@ -119,8 +119,7 @@ class CRM_Core_QuickForm_Action_Display extends CRM_Core_QuickForm_Action {
     // Deprecated - use snippet=6 instead of json=1
     $json = CRM_Utils_Request::retrieve('json', 'Boolean', CRM_Core_DAO::$_nullObject);
     if ($json) {
-      echo json_encode($form);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($form);
     }
 
     $template->assign('form', $form);
index 355c473f74c1f7f0f2d08de0de58c85c52ac3793..530201327180692f31e30ce19292308b913fd4d4 100644 (file)
@@ -64,8 +64,7 @@ GROUP BY cv.label";
     while ($dao->fetch()) {
       $results[] = array('id' => $dao->id, 'text' => $dao->label);
     }
-    echo json_encode($results);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($results);
   }
 
 }
index 98c1a43a4d9e5a682f3f69b775e4ea7ad1ed77e8..eea4ff4bc4c25bf089a4586442f44cab6ae187be 100644 (file)
@@ -90,8 +90,7 @@ class CRM_Financial_Page_AJAX {
         ) + $selectedArray;
       }
     }
-    echo json_encode($elements);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($elements);
   }
 
   /**
@@ -150,8 +149,7 @@ class CRM_Financial_Page_AJAX {
         }
       }
     }
-    echo json_encode($elements);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($elements);
   }
 
   /**
@@ -164,8 +162,7 @@ class CRM_Financial_Page_AJAX {
     }
 
     $elements = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Product', $_GET['_value'], 'financial_type_id');
-    echo json_encode($elements);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($elements);
   }
 
   /**
@@ -257,8 +254,7 @@ class CRM_Financial_Page_AJAX {
         }
       }
     }
-    echo json_encode($response);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($response);
   }
 
   static function getFinancialTransactionsList() {
@@ -490,8 +486,7 @@ class CRM_Financial_Page_AJAX {
     else {
       $status = array('status' => ts("This batch is configured to include only transactions using %1 payment method. If you want to include other transactions, please edit the batch first and modify the Payment Method.", array( 1 => $paymentInstrument)));
     }
-    echo json_encode($status);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($status);
   }
 
   static function getBatchSummary() {
@@ -512,7 +507,6 @@ class CRM_Financial_Page_AJAX {
         'opened_date' => CRM_Utils_Date::customFormat($batchInfo->created_date),
       );
 
-    echo json_encode($batchSummary);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($batchSummary);
   }
 }
index cffa28a9ef9248aebb7ee4f6f408c33c03bd8293..8f6887e4d623888f894864bcf2382caa67ebb1f3 100644 (file)
@@ -45,8 +45,7 @@ class CRM_Group_Page_AJAX {
       $params['rp']   = 0;
       $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
 
-      echo json_encode($groups);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($groups);
     }
     else {
       $sortMapper = array(
index 4ae393f0086638b79819eccca60af32e549a4bcd..44b45a30dd2e78addfb566c6f999d9cc9d2dccbc 100644 (file)
@@ -56,8 +56,7 @@ class CRM_Mailing_Page_AJAX {
       'pdf_format_id' => $messageTemplate->pdf_format_id,
     );
 
-    echo json_encode($messages);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($messages);
   }
 
   /**
index c49e5269683e634872a5ba869734f6e9676ee584..460081eb2d043b3bf34fb4faa72504287fe391ef 100644 (file)
@@ -47,8 +47,7 @@ class CRM_Member_Page_AJAX {
       $details['auto_renew'] = '';
       $details['total_amount'] = '';
 
-      echo json_encode($details);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($details);
     }
     $memType = CRM_Utils_Type::escape($_POST['mtype'], 'Integer');
 
@@ -68,8 +67,7 @@ WHERE   id = %1";
     $details['total_amount'] = CRM_Utils_Money::format($details['total_amount'], NULL, '%a');
     $options = array(ts('No auto-renew option'), ts('Give option, but not required'), ts('Auto-renew required '));
     $details['auto_renew'] = CRM_Utils_Array::value('auto_renew', $options[$details]);
-    echo json_encode($details);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($details);
   }
 }
 
index e30fbe6d97b56a001307bd3fe085e70205500244..14f0812808b822f95e6fb9d28b7cc6ed0e907151 100644 (file)
@@ -168,8 +168,7 @@ class CRM_Queue_ErrorPolicy {
     if (is_object($activeQueueRunner)) {
       $response['last_task_title'] = $activeQueueRunner->lastTaskTitle;
     }
-    echo json_encode($response);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($response);
   }
 }
 
index 2b87ac57925360a10e380331a5fa7505220f30ad..bf6d267e4c2c10f13825616cdce4b3b6347aae22 100644 (file)
@@ -112,8 +112,7 @@ class CRM_Queue_Page_AJAX {
         CRM_Core_Error::debug_var("CRM_Queue_Page_AJAX_{$op}_error", $result);
       }
     }
-        echo json_encode($result);
-        CRM_Utils_System::civiExit();
+        CRM_Utils_JSON::output($result);
     }
   }
 
index 2a8555583d8a6267231cc8d74ccf30e92d031671..4b3ec9dacd57987c85a44710d7ef3532ac6491f1 100644 (file)
@@ -47,7 +47,6 @@ class CRM_UF_Page_AJAX {
 
     $isMultiple = CRM_Core_BAO_CustomField::isMultiRecordField($customId);
     $isMultiple = array('is_multi' => $isMultiple);
-    echo json_encode($isMultiple);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($isMultiple);
   }
 }
index 6b2b33282be6ac93052c0420c0ffd3bd43cd2f9e..6c16846939ccc5c0bb3a574c520fef2b9da7c5d0 100644 (file)
@@ -81,8 +81,7 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page {
    */
   static function getSchemaJSON() {
     $entityTypes = explode(',', $_REQUEST['entityTypes']);
-    echo json_encode(self::getSchema($entityTypes));
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output(self::getSchema($entityTypes));
   }
 
   /**
index 00287a5eaab62c25176b42a434b76782f3ca6684..3052403c25e33e41a916d09a5519956aaed0d838 100644 (file)
@@ -44,8 +44,7 @@ class CRM_Utils_JSON {
    */
   static function output($input) {
     header('Content-Type: application/json');
-    echo json_encode($input);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output($input);
   }
 
   /**
index 6539aade422fe283a20aab84d9dffcace49dd51b..010cfe8156b0c69759895083d89c3de1af7a50be 100644 (file)
@@ -421,8 +421,7 @@ class CRM_Utils_REST {
     if (array_key_exists('json', $requestParams) &&  $requestParams['json'][0] == "{") {
       $params = json_decode($requestParams['json'], TRUE);
       if($params === NULL) {
-        echo json_encode(array('is_error' => 1, 'error_message', 'Unable to decode supplied JSON.'));
-        CRM_Utils_System::civiExit();
+        CRM_Utils_JSON::output(array('is_error' => 1, 'error_message', 'Unable to decode supplied JSON.'));
       }
     }
     foreach ($requestParams as $n => $v) {
@@ -541,16 +540,13 @@ class CRM_Utils_REST {
           'reason' => 'CSRF suspected',
         )
       );
-      echo json_encode($error);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($error);
     }
     if (empty($requestParams['entity'])) {
-      echo json_encode(civicrm_api3_create_error('missing entity param'));
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output(civicrm_api3_create_error('missing entity param'));
     }
     if (empty($requestParams['entity'])) {
-      echo json_encode(civicrm_api3_create_error('missing entity entity'));
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output(civicrm_api3_create_error('missing entity entity'));
     }
     if (!empty($requestParams['json'])) {
       $params = json_decode($requestParams['json'], TRUE);
@@ -558,8 +554,7 @@ class CRM_Utils_REST {
     $entity = CRM_Utils_String::munge(CRM_Utils_Array::value('entity', $requestParams));
     $action = CRM_Utils_String::munge(CRM_Utils_Array::value('action', $requestParams));
     if (!is_array($params)) {
-      echo json_encode(array('is_error' => 1, 'error_message', 'invalid json format: ?{"param_with_double_quote":"value"}'));
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output(array('is_error' => 1, 'error_message', 'invalid json format: ?{"param_with_double_quote":"value"}'));
     }
 
     $params['check_permissions'] = TRUE;
@@ -600,8 +595,7 @@ class CRM_Utils_REST {
           'reason' => 'CSRF suspected',
         )
       );
-      echo json_encode($error);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($error);
     }
 
     $q = CRM_Utils_Array::value('fnName', $requestParams);