Reputation: 459
I need to add a HTTP header to all Ajax (XHR) Requests of Wicket. I've tried 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');
});
It doesn't work.
What did I wrong?
How can I solve this?
SOLUTION
Wicket uses it's own stuff to register global listeners.
Wicket.Event.subscribe('/ajax/call/beforeSend', function(jqEvent, attributes, jqXHR, errorThrown, textStatus) {
jqXHR.setRequestHeader('X-My-Header', 'value');
});
Upvotes: 2
Views: 900
Reputation: 2511
I don't know why your attempts failed, but wicket provides support for such requirements with AJAX global listeners. Search for paragraph 'Global listener' in this chapter:
https://ci.apache.org/projects/wicket/guide/7.x/guide/ajax.html#ajax_6
Upvotes: 3