Solve Cross Origin Resource Sharing with Flask

后端 未结 9 760
面向向阳花
面向向阳花 2020-11-28 03:59

For the following ajax post request for Flask (how can I use data posted from ajax in flask?):

$.ajax({
    url: \"http://127.0.0.1         


        
9条回答
  •  半阙折子戏
    2020-11-28 04:04

    I struggled a lot with something similar. Try the following:

    1. Use some sort of browser plugin which can display the HTML headers.
    2. Enter the URL to your service, and view the returned header values.
    3. Make sure Access-Control-Allow-Origin is set to one and only one domain, which should be the request origin. Do not set Access-Control-Allow-Origin to *.

    If this doesn't help, take a look at this article. It's on PHP, but it describes exactly which headers must be set to which values for CORS to work.

    CORS That Works In IE, Firefox, Chrome And Safari

提交回复
热议问题