No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '…' is therefore not allowed access

后端 未结 11 1859
醉话见心
醉话见心 2020-11-22 14:27

I\'m using .htaccess to rewrite urls and I used html base tag in order to make it work.

Now, when I try to make an ajax request I get the following error:

11条回答
  •  遥遥无期
    2020-11-22 14:35

    you have to put the headers keys/values in options method response. for example if you have resource at http://mydomain.com/myresource then, in your server code you write

    //response handler
    void handleRequest(Request request, Response response) {
        if(request.method == "OPTIONS") {
           response.setHeader("Access-Control-Allow-Origin","http://clientDomain.com")
           response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
           response.setHeader("Access-Control-Allow-Headers", "Content-Type");
        }
    
    
    
    }
    

提交回复
热议问题