/** * Send the string to a browser and exit * * @param array $arrJSON * @param int httpCode default is 200 * @param array $headers * @param boolean $addJSTags if true, then * string will be sent as an HTML page that contains * javascript * Javascript will pass the json object to * the parent window's function fParseResponse * but only if parent object exists and contains * fParseQfJson script */ public static function sendJSON(array $aJSON, array $headers = null, $httpCode = 200, $addJSTags = false) { if (Request::isIframe() || !empty($addJSTags)) { self::sendJsonPage($aJSON); session_write_close(); throw new \OutOfBoundsException(); } $contentType = "Content-Type: text/json; charset=UTF-8"; $res = json_encode($aJSON); d('Sending json: ' . $res); header("HTTP/1.1 " . $httpCode . " OK"); header($contentType); echo $res; session_write_close(); fastcgi_finish_request(); //exit(); throw new \OutOfBoundsException(); }
/** * Send the string to a browser and exit * * @param array $aJSON * @param array $headers * @param int $httpCode httpCode default is 200 * @param boolean $addJSTags if true, then * string will be sent as an HTML page that contains * javascript * Javascript will pass the json object to * the parent window's function fParseResponse * but only if parent object exists and contains * fParseQfJson script * * @throws \OutOfBoundsException * @internal param array $arrJSON */ public static function sendJSON(array $aJSON, array $headers = null, $httpCode = 200, $addJSTags = false) { if (Request::isIframe() || !empty($addJSTags)) { self::sendJsonPage($aJSON); session_write_close(); throw new \OutOfBoundsException(); } $contentType = "Content-Type: text/json; charset=UTF-8"; $res = \json_encode($aJSON); /** * Must set error_reporting to 0 to deal with * those mongo notices. Any notice or error * will render the json text invalid */ error_reporting(0); d('Sending json: ' . $res); header("HTTP/1.1 " . $httpCode . " OK"); header($contentType); echo $res; \session_write_close(); fastcgi_finish_request(); //exit(); throw new \OutOfBoundsException(); }