diff --git a/phpgwapi/inc/class.egw_json.inc.php b/phpgwapi/inc/class.egw_json.inc.php index 053172786b..c7dc028cfc 100644 --- a/phpgwapi/inc/class.egw_json.inc.php +++ b/phpgwapi/inc/class.egw_json.inc.php @@ -184,9 +184,10 @@ class egw_json_response */ public function sendResult() { - $this->sendHeader(); + $inst = self::get(); - echo $this->getJSON(); + $inst->sendHeader(); + echo $inst->getJSON(); } /** @@ -202,7 +203,7 @@ class egw_json_response */ protected function addGeneric($key, $data) { - $this->responseArray[] = array( + self::get()->responseArray[] = array( 'type' => $key, 'data' => $data, ); @@ -218,10 +219,11 @@ class egw_json_response public function data($data) { /* Only allow adding the data response once */ - if (!$this->hasData) + $inst = self::get(); + if (!$inst->hasData) { - $this->addGeneric('data', $data); - $this->hasData = true; + $inst->addGeneric('data', $data); + $inst->hasData = true; } else { @@ -365,12 +367,10 @@ class egw_json_response { if (is_string($url)) { - $this->addGeneric('js', $url); + self::get()->addGeneric('js', $url); } } - - /** * Returns the actual JSON code generated by calling the above "add" function. * @@ -378,8 +378,10 @@ class egw_json_response */ public function getJSON() { + $inst = self::get(); + /* Wrap the result array into a parent "response" Object */ - $res = array('response' => $this->responseArray); + $res = array('response' => $inst->responseArray); return json_encode($res); //PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); } @@ -389,7 +391,9 @@ class egw_json_response */ public function __destruct() { - $this->sendResult(); + //Only send the response if this instance is the singleton instance + if ($this == self::get()) + $this->sendResult(); } } @@ -426,7 +430,6 @@ class xajaxResponse extends egw_json_response $this->script("try{window['".$func."'].apply(window, ".json_encode($args).");} catch(e) {_egw_json_debug_log(e);}"); } - public function addIncludeCSS($url) { $this->includeCSS($url);