I am trying to include a custom HTTP header in all Ajax (XHR) requests made by Wicket. I attempted the following:
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('X-My-Header', 'value');
}
});
and
$(document).ajaxSend(function(e, xhr, options) {
xhr.setRequestHeader('X-My-Header', 'value');
});
Unfortunately, these methods did not work as expected.
What mistake did I make?
How can I resolve this issue?
SUGGESTED FIX
Wicket utilizes its own mechanisms for registering global event listeners.
Wicket.Event.subscribe('/ajax/call/beforeSend', function(jqEvent, attributes, jqXHR, errorThrown, textStatus) {
jqXHR.setRequestHeader('X-My-Header', 'value');
});