CRM-15926 - CRM_Contact_Page_AJAX - Output JSON headers
authorTim Otten <totten@civicrm.org>
Mon, 9 Feb 2015 23:40:57 +0000 (15:40 -0800)
committerTim Otten <totten@civicrm.org>
Tue, 10 Feb 2015 13:22:01 +0000 (05:22 -0800)
CRM/Contact/Page/AJAX.php

index a1b4f10eb0537adc988554bb3a5b1801f4c92623..3e9f3c1600532cf257921f13cfa1fa7c676b81ea 100644 (file)
@@ -192,7 +192,7 @@ class CRM_Contact_Page_AJAX {
       $contactList[] = array('id' => $value['id'], 'text' => implode(' :: ', $view));
     }
 
-    CRM_Utils_System::civiExit(json_encode($contactList));
+    CRM_Utils_JSON::output($contactList);
   }
 
   /**
@@ -330,6 +330,7 @@ class CRM_Contact_Page_AJAX {
   }
 
   static function groupTree() {
+    header('Content-Type: application/json');
     $gids = CRM_Utils_Type::escape($_GET['gids'], 'String');
     echo CRM_Contact_BAO_GroupNestingCache::json($gids);
     CRM_Utils_System::civiExit();
@@ -512,7 +513,7 @@ ORDER BY sort_name ";
     }
 
     if ($json) {
-      echo json_encode($elements);
+      CRM_Utils_JSON::output($elements);
     }
     CRM_Utils_System::civiExit();
   }
@@ -592,8 +593,7 @@ ORDER BY sort_name ";
       || !$signer->validate($_REQUEST['sig'], $_REQUEST)
     ) {
       $user = array('name' => 'error');
-      echo json_encode($user);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($user);
     }
 
     $config = CRM_Core_Config::singleton();
@@ -607,13 +607,15 @@ ORDER BY sort_name ";
     if (isset($errors['cms_name']) || isset($errors['name'])) {
       //user name is not availble
       $user = array('name' => 'no');
-      echo json_encode($user);
+      CRM_Utils_JSON::output($user);
     }
     else {
       //user name is available
       $user = array('name' => 'yes');
-      echo json_encode($user);
+      CRM_Utils_JSON::output($user);
     }
+
+    // Not reachable: JSON::output() above exits.
     CRM_Utils_System::civiExit();
   }
 
@@ -723,7 +725,7 @@ LIMIT {$offset}, {$rowCount}
           }
         }
         if ($result) {
-          echo json_encode($result);
+          CRM_Utils_JSON::output($result);
         }
       }
     }
@@ -794,7 +796,7 @@ LIMIT {$offset}, {$rowCount}
     }
 
     if ($result) {
-      echo json_encode($result);
+      CRM_Utils_JSON::output($result);
     }
     CRM_Utils_System::civiExit();
   }