Если AJAX validateCsrf успешна то fetch validateCsrf провалена
Для примера простая задача загрузка данных для select
Код: Выделить всё
let hAddress = document.querySelector(".house-address");
let hService = document.querySelector(".house-service");
let pUrl = '/index.php?r=options%2Fservice-house';
let param = document.querySelector('meta[name="csrf-param"]').content;
let token = document.querySelector('meta[name="csrf-token"]').content;
let pData = {};
pData[param] = token;
hAddress.addEventListener('change', function () {
let pVal = this.options[this.selectedIndex].value;
pData['house_id'] = pVal;
getOptionsByFetchPost(pUrl);
});
function getOptionsByFetchPost(pUrl) {
fetch(pUrl, {
method: 'POST',
body: JSON.stringify(pData),
headers: {
'Content-Type': 'text/html'
}
})
.then((response) => {
return response.text()
})
.then((html) => {
// console.log(html);
hService.innerHTML = html;
})
.catch(err => console.error(err))
;
}
Выбрасывает в /web/Controller /web/Request->validateCsrfToken()...