diff --git a/src/widgets/HookTrait.php b/src/widgets/HookTrait.php index 3d5353ab..5bab592d 100644 --- a/src/widgets/HookTrait.php +++ b/src/widgets/HookTrait.php @@ -3,17 +3,21 @@ namespace hipanel\widgets; use hipanel\actions\Action; +use yii\helpers\Json; use yii\web\View; trait HookTrait { + public ?string $url = null; + public function registerJsHook(string $reqHeaderParamName): void { $id = $this->getId(); $headerName = Action::EXPECTED_AJAX_RESPONSE_HEADER_NAME; + $url = $this->url ? Json::encode($this->url) : 'document.URL'; $this->view->registerJs("$.ajax({ type: 'GET', - url: document.URL, + url: {$url}, beforeSend: xhr => { xhr.setRequestHeader('{$headerName}', '{$reqHeaderParamName}'); },