htmx:before:response
Срабатывает после fetch(), до response.text()
Событие htmx:before:response срабатывает после получения ответа fetch, но до того, как htmx прочитает тело ответа.
Когда срабатывает
После получения ответа от сети, до чтения тела или начала подмены.
Данные события
-
ctx.response.raw— исходный объект Response (тело ещё не прочитано) -
ctx.response.status— код состояния HTTP -
ctx.response.headers— заголовки ответа
Пример
htmx.on('htmx:before:response', (evt) => {
const status = evt.detail.ctx.response.status;
const headers = evt.detail.ctx.response.headers;
console.log('Response status:', status);
console.log('Content-Type:', headers.get('content-type'));
// Handle error status codes before body is consumed
if (status >= 400) {
console.log('Error response received');
}
}); Отмените это событие, чтобы пропустить обычную обработку ответа, включая чтение тела и подмену.
Licensed under the Zero-Clause BSD License.
https://four.htmx.org/reference/events/htmx-before-response/