Bug 36084: Fix is_ajax by setting X-Requested-With header

Some svc scripts (and controllers) are using using is_ajax to guess if
it's an AJAX request.
$.ajax is setting the (non standard) X-Requested-With header, but the
low level JS 'fetch' does not.

This patch set it in http-client.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2024-02-20 10:00:11 +01:00
parent 50f383de75
commit 6a9ff124a5
Signed by: jonathan.druart
GPG key ID: A085E712BEF0E0F0

View file

@ -17,8 +17,9 @@ class Dialog {
class HttpClient {
constructor(options = {}) {
this._baseURL = options.baseURL || "";
this._headers = options.headers || {
this._headers = options.headers || { // FIXME we actually need to merge the headers
"Content-Type": "application/json;charset=utf-8",
"X-Requested-With": "XMLHttpRequest"
};
this.csrf_token = $('meta[name="csrf-token"]').attr("content");
}