Keep getting No 'Access-Control-Allow-Origin' error with XMLHttpRequest

后端 未结 5 1043
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 08:58

I would have solved this issue by using jQuery $.ajax function but in this case jQuery is not option. Instead I am going with CORS request. I feel there is so

5条回答
  •  遥遥无期
    2020-12-15 09:19

    Your server's response allows the request to include three specific non-simple headers:

    Access-Control-Allow-Headers:origin, x-requested-with, content-type
    

    but your request has a header not allowed by the server's response:

    Access-Control-Request-Headers:access-control-allow-origin, content-type
    

    All non-simple headers sent in a CORS request must be explicitly allowed by the Access-Control-Allow-Headers response header. The unnecessary Access-Control-Allow-Origin header sent in your request is not allowed by the server's CORS response. This is exactly what the "...not allowed by Access-Control-Allow-Headers" error message was trying to tell you.

    There is no reason for the request to have this header: it does nothing, because Access-Control-Allow-Origin is a response header, not a request header.

    Solution: Remove the setRequestHeader call that adds a Access-Control-Allow-Origin header to your request.

提交回复
热议问题