N
N
nezzard2015-02-09 22:23:33
JavaScript
nezzard, 2015-02-09 22:23:33

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

2 answer(s)
S
Sergey Kolchenko, 2015-11-13
@unikz

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...

V
Veniamin Lytkin, 2015-02-10
@Epsil0neR

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 question

Ask a Question

731 491 924 answers to any question