public function handleAjaxCall() { header("Content-Type: application/json; charset=UTF-8"); if ($_SERVER['REQUEST_METHOD'] != 'POST') { echo json_encode(array('error' => 'only POSTing is allowed')); } else { $input = file_get_contents("php://input"); $json = json_decode($input); $method = $json->method; $params = $json->params; $this->ajaxEndpoint->storage = $this; try { $reflectionMethod = new reflectionMethod($this->ajaxEndpoint, $method); $retval = $reflectionMethod->invokeArgs($this->ajaxEndpoint, $params); echo json_encode(array('result' => $retval)); } catch (Exception $e) { echo json_encode(array('error' => $e->getMessage())); } } }