Answer the question
In order to leave comments, you need to log in
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;
}
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);
});
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question