V
V
Vladimir Golub2018-03-28 16:13:09
JavaScript
Vladimir Golub, 2018-03-28 16:13:09

How to make an AJAX request to the init.php file in bitrix?

Content of init.php

$id = 0;

AddEventHandler("main", "OnBeforeProlog", "getUserId", 50);

function getUserId()
{
    global $USER;
    $id = $USER->GetID();
}


if($_GET['getData'] == 'userId') {
    echo $id;
}

Request
axios.get('/bitrix/php_interface/init.php', {
            params: { 'getData' : 'userId' }
        })
        .then(response => {
            this.userId = response.data;
            console.log(this.userId);
        })
        .catch(e => {
            this.errors.push(e);
        });

Error 403, if you just create a file in a folder with a file, then everything is OK, but then there is no access to the user variable.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Epifanov, 2018-03-28
@RazerVG

no need to make requests to init.php . create a special handler file and send requests there.
in order to be able to use the Bitrix API, include the prologue at the beginning of the file

require_once($_SERVER['DOCUMENT_ROOT']. "/bitrix/modules/main/include/prolog_before.php");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question