我想从一个伪装成远程网络服务器的静态页面发布到我的Flask
应用中,因为Flask-uWSGI-WebSocket
而在uwsgi
后面运行。CORS阻止来自jQuery的帖子
每次我张贴到我的服务器,帖子被阻止,因为CORS的: XMLHttpRequest cannot load http://127.0.0.1:5000/tnw/post. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
我已经安装了flask-cors
和起源设置为*
,但我仍然不能得到它去。我还有什么在这里错过?
我的帖子: $("#ajaxbutton").click(function() { var json = JSON.stringify(generate_json()); $.post('http://127.0.0.1:5000/tnw/post', json); });
如何访问发出CORS请求的页面?它是通过http://还是file://(后者会给你一个'null'的起源,你不想这么做)。如果是后者,请尝试使用简单的http服务器(例如python -m SimpleHTTPServer)。另外,您是否需要在此端点上进行任何类型的身份验证?如果是这样,并且它是基于cookie的,则需要将'withCredentials' xhr字段设置为'true',以允许cookie与请求一起发布([docs](http://api.jquery.com/) jQuery.ajax /#jQuery的Ajax的设置))。 – jonafato
把它变成答案,我可以接受它。 – ruipacheco
这是个问题吗?现在添加一个答案,但我想确保它为未来的读者解决正确的问题。 – jonafato