This event is emitted before an AJAX request is sent over the network.
Only requests that are sent via Unpoly features
(like [up-follow]
or up.request()
) will trigger this event.
When making a requests using fetch()
or XMLHttpRequest
, no event is emitted.
The event is emitted on the layer that caused the request.
Listeners to up:request:load
can inspect or
mutate the request options
before it is loaded.
For example, this listeners changes requests to /stocks
to include a custom header and have a timeout of 10 seconds:
up.on('up:request:load', (event) => {
if (event.request.url === '/stocks') {
event.request.headers['X-Client-Time'] = Date.now().toString()
event.request.timeout = 10_000
}
})
The request that will be sent.
Listeners can inspect or mutate request options before it is sent.
The layer this request is associated with.
If this request is intended to update an existing fragment, this is that fragment's layer.
If this request is intended to open an overlay, the associated layer is the future overlay's parent layer.
Aborts the request before it is sent.