Reputation: 638
I'm trying to set a custom header with pJax so I can render things on the server side. Per the pjax docs, I can use pjax:beforeSend
to set xhr headers.
Getting the following error:
typeerror xhr.setrequestheader is not a function
The code i've tried:
$(document).on('pjax:beforeSend', function(xhr) {
if ($(event.target).data('rendertimeline') !== undefined) {
xhr.setRequestHeader('X-RENDERTIMELINE', 'true');
}
});
basically, i'm adding a data attribute to certain links and would link to check for that attribute. if its there, send a custom HTTP header along side the standard HTTP_X_PJAX header. Seemed fairly simple but i'm coming up short somewhere.
Upvotes: 3
Views: 837
Reputation: 7674
Looks like you have started using PJAX recently first argument is not xhr but event object add that and it should work.Don't know why they skipped it in docs but most events like start,end etc will have event as their first argument .
$(document).on('pjax:beforeSend', function(event,xhr, options)
Upvotes: 1