How can I download a script using Javascript and supply a header to the GET?

Posted by Alan on Stack Overflow See other posts from Stack Overflow or by Alan
Published on 2014-06-01T02:21:05Z Indexed on 2014/06/01 3:26 UTC
Read the original article Hit count: 121

Filed under:

I have this method for downloading a script:

var script = document.createElement('script');
    script.setAttribute("src", url);
    document.getElementsByTagName("head")[0].appendChild(script);

This gives me a GET like this:

GET http://127.0.0.1:17315/Scripts/abc.js HTTP/1.1

However I need to add a header:

Authorization: Bearer Ipnsfm9h1MWYIM0n1ng

Can anyone tell me how I can add a header when I am using Javascript to perform the GET?

© Stack Overflow or respective owner

Related posts about JavaScript