Elgg\ActionsService::ajaxForwardHook PHP Méthode

ajaxForwardHook() public méthode

See also: ajax_forward_hook
Deprecation: 2.3
public ajaxForwardHook ( $hook, $reason, $forward_url, $params )
    public function ajaxForwardHook($hook, $reason, $forward_url, $params)
    {
        if (!elgg_is_xhr()) {
            return;
        }
        // grab any data echo'd in the action
        $output = ob_get_clean();
        if ($reason == 'walled_garden' || $reason == 'csrf') {
            $reason = '403';
        }
        $status_code = (int) $reason;
        if ($status_code < 100 || $status_code > 299 && $status_code < 400 || $status_code > 599) {
            // We only want to preserve OK and error codes
            // Redirect responses should be converted to OK responses as this is an XHR request
            $status_code = ELGG_HTTP_OK;
        }
        $response = elgg_ok_response($output, '', $forward_url, $status_code);
        $headers = $response->getHeaders();
        $headers['Content-Type'] = 'application/json; charset=UTF-8';
        $response->setHeaders($headers);
        _elgg_services()->responseFactory->respond($response);
        exit;
    }