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?
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')));
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