加载json文件时出现以下错误:
无法加载http://localhost/sandbox/data.json?_=1505732125859:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许访问源'http://localhost:5000‘。
#...
from flask_cors import CORS
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})
@app.route('/')
def index():
return render_template('index.html')尝试过此解决方案..但是仍然得到相同的错误Javascript - No 'Access-Control-Allow-Origin' header is present on the requested resource
发布于 2017-09-18 20:48:23
您在错误的服务器上设置了CORS权限。
http://localhost:5000上的网页正在向http://localhost发出请求。
您的标头授予每个站点(*)访问http://localhost:5000上的数据的权限,但您试图访问http://localhost上的数据。
您需要在http://localhost上设置CORS权限。
This answer解释了背景。
https://stackoverflow.com/questions/46277643
复制相似问题