Add CORS header to an http request using Ajax

后端 未结 2 551
情歌与酒
情歌与酒 2020-11-27 23:50

I have developed a Restfull application and I\'d like to add another web application to consume its services so I make this Ajax call :

 $.ajax({
                    


        
2条回答
  •  隐瞒了意图╮
    2020-11-28 00:40

    somehow i redirected to this question to get the solution for my Flask application. Since the server has to send the response back to the header, the CORS has to set in the server side. In my case i was trying to send the request from

    client http://127.0.0.1:8081/

    to

    server http://127.0.0.1:5051

    So i set the cors policy to allow the origin in the client side

    headers: {  "Access-Control-Allow-Origin:": "*"},
    

    and for the server side, flask provides library to allow the cors

    from flask_cors import CORS
    app = Flask(__name__)
    
    CORS(app)
    

    it actually got resolved the issue

提交回复
热议问题