跨域ajax
在我阅读 此内容后文章,我的理解是,为了允许跨域ajax调用,我必须将服务器响应设置为Access-Control-Allow-Origin: *< /strong>(公开测试目的),这是我的服务器代码,Python 中的 Google AppEngine
self.response.headers.add_header('Access - Control - Allow - Origin:*')
self.response.headers.add_header('content-type', 'application/json', charset = 'utf-8')
self.response.out.write(simplejson.dumps(Jsonobject))
我不知道这是否正确。我的 Ajax 调用
xhr.open("get", "http://example.com", true);
xhr.setRequestHeader("Access-Control-Allow-Origin","example");
总是收到此错误。 Access-Control-Allow-Origin 不允许 Origin null。我该如何配置?非常感谢
After I read this article, what I understand is that in order to allow cross-domain ajax calls, I have to set the server response to be Access-Control-Allow-Origin: *(public for testing purpose), and here is my server code, Google AppEngine in Python
self.response.headers.add_header('Access - Control - Allow - Origin:*')
self.response.headers.add_header('content-type', 'application/json', charset = 'utf-8')
self.response.out.write(simplejson.dumps(Jsonobject))
I don't know if that is correct. And my Ajax call
xhr.open("get", "http://example.com", true);
xhr.setRequestHeader("Access-Control-Allow-Origin","example");
I always got this error. Origin null is not allowed by Access-Control-Allow-Origin. How do I configure this? Thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Access-Control-Allow-Origin
,而不是Access - Control - Allow - Origin
self.response.headers.add_header (str)
有效,也许是self.response.headers.add_header(key, name)
?*
域不起作用(至少不适用于所有浏览器)。您必须使用准确的域名、全名和协议。就像http://example.com
Origin
标头,用于 ajax 调用。我不知道如何配置原始xhr
,但我猜它是浏览器本身制作的,你无法修改这个值。无论如何,您的域名不是example
Access-Control-Allow-Origin
, notAccess - Control - Allow - Origin
self.response.headers.add_header(str)
is valid, maybeself.response.headers.add_header(key, name)
?*
domain doesn't work (at least not for all browsers). You have to use exact domain, full name, with protocol. Likehttp://example.com
Origin
header, for ajax call. I'm not sure how to configure rawxhr
, but I guess that it's made by browser itself, and you can't modify this value. Anyway, your domain notexample
也许这些代码行可以解决您的问题。
您可以做一件事,只需设置 Access-Control-Allow-Origin & CustomeHeaders 中的 Access-Control-Allow-Headers 您的 Web 服务 web.config 文件。
如果您只想允许特定域,您可以使用域的特定值而不是 * 值来实现
May be these lines of code solve your problem.
You can do one thing for that just need to set Access-Control-Allow-Origin & Access-Control-Allow-Headers in CustomeHeaders your web service web.config file.
If you want to allow only for specific domain , you can do that with specific value of domain instead of * value