Answer the question
In order to leave comments, you need to log in
How to pass header via AJAX?
Good evening, how to correctly pass through the AJAX header?
I try like this
headers: {}
but I get an error
Refused to set unsafe header "origin"
jquery.min.js:4 Refused to set unsafe header "referer"
jquery.min.js:4 Refused to set unsafe header "User-Agent"
Answer the question
In order to leave comments, you need to log in
Header substitutions such as Referer, Origin, and others are prohibited by the XMLHttpRequest specification. The full list of headers prohibited from editing can be found in the specification itself: www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest-s...
Use the beforeSend function of jQuery.ajax and set headers to the first xhr argument via the setRequestHeader function :
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: { signature: authHeader },
type: "GET",
beforeSend: function(xhr){xhr.setRequestHeader('X-Test-Header', 'test-value');},
success: function() { alert('Success!' + authHeader); }
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question