首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CORS阻塞来自jQuery的帖子

CORS阻塞来自jQuery的帖子
EN

Stack Overflow用户
提问于 2014-03-13 16:41:38
回答 1查看 763关注 0票数 0

我正试图从一个假装是远程web服务器的静态页面发布到我的Flask应用程序中,因为Flask-uWSGI-WebSocket而运行在uwsgi之后。

每次我投递到服务器时,帖子都会因为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); });

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-13 21:04:23

我认为这是两个问题之一:

  • 您正在访问通过file://协议而不是http://请求CORS的页面。这导致您拥有一个origin of 'null'。尝试使用通过http://访问它(例如,python -m SimpleHTTPServer)。
  • 端点需要基于cookie的身份验证吗?默认情况下,jQuery在CORS请求中省略cookies。如果您需要在请求中发送cookie,请将{xhrFields: withCredentials: true}添加到ajax请求(文档)中。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22385264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档