1

Im trying to make a request from one application to another. So i created some headers which are required by my application and filled them in for the Ajax Request. Here is my code:

$.ajax({
    method: 'GET',
    url: 'http://my-domain.com/apps/filters/get-filters',
    beforeSend: function(request){
        request.setRequestHeader("X-Webshop-Domain", window.location.host);
        request.setRequestHeader("X-Language", $('html').attr('lang'));
        request.setRequestHeader("X-Request-Protocol", window.location.protocol);
        request.setRequestHeader("X-Api-Version", '2');
    },
    headers: {
        "X-Webshop-Domain": window.location.host,
        "X-Language": $('html').attr('lang'),
        "X-Request-Protocol": window.location.protocol,
        "X-Api-Version": '2',
    },
    data: {}, success: function ( response )
    {

    }
});

Now when i load a page, this method is called but no response given. It gives me the "Header not allowed" issue. But when i check in my network tab (developer tools Chrome) i see my request, i see some headers but none of those. Does anybody has a idea how this is possible or what im doing wrong?

1 Answer 1

1

In case of CORS (cross domain requests), only basic headers are allowed. You will need to add the headers you wish to send to the server's response header:

Access-Control-Allow-Headers: X-Webshop-Domain, ...

Here's a related question you may find useful: Ajax Request header field Key is not allowed by Access-Control-Allow-Headers

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, you helped me out a lot! :D

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.