1

If I set a custom header using php on the server side like this:

header('customheader: yay');

How do I receive this on the client side using javascript?

2 Answers 2

1

You will need to send another request to retrieve the headers. It's often not an issue if the url is cached. In this case, I will recommend you to use fetch API for the task.

fetch('/whatever/url').then(response => console.log(response.headers.get('customheader')));
Sign up to request clarification or add additional context in comments.

1 Comment

0

use $.ajax().done() event jqXHR parameter

jqXHR.done(function( data, textStatus, jqXHR ) {});

Then call getResponseHeader() on the jqXHR object to get a list of response headers

2 Comments

Is this for a basic http request or just ajax? Looking for a general solution that uses pure javascript.
jqXHR is a wrapper with added properties, never the less getResponseHeader() is standard xhr.spec.whatwg.org/#the-getresponseheader()-method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.