问题描述
我在我的网站中使用 CometChat
,最近我的用户在接收消息时遇到了这个问题.在 FireBug 中检查后,我意识到脚本失败一定是由于 CORS 保护(由于以下错误).
I'm using CometChat
in my website and recently my users art having this problem with receiving messages. After inspection in FireBug i realized it must be because of the CORS protection (due to the following error) that the script is failing.
跨域请求被阻止:同源策略不允许读取远程资源在http://x3.chatforyoursite.com/subscribe/...这可以通过将资源移动到同一域或启用 CORS.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://x3.chatforyoursite.com/subscribe/... This can be fixed by moving the resource to the same domain or enabling CORS.
现在我想知道我应该在哪里启用 CORS,因为它是在我自己的服务器上启用的,我无法访问 CometChat
服务器.
Now I'm wondering where should I enable CORS because it is enabled on my own server and I have no access to the CometChat
server.
推荐答案
x3.chatforyoursite.com
的服务器需要输出如下header:
The server at x3.chatforyoursite.com
needs to output the following header:
Access-Control-Allow-Origin:http://www.example.com
http://www.example.com
是您的网站地址.您应该在 chatforyoursite.com
上检查您的设置,看看您是否可以启用此功能 - 如果不能,他们的技术支持可能是解决此问题的最佳方法.但是,要回答您的问题,您需要远程站点允许您的站点访问 AJAX 响应客户端.
Where http://www.example.com
is your website address. You should check your settings on chatforyoursite.com
to see if you can enable this - if not their technical support would probably be the best way to resolve this. However to answer your question, you need the remote site to allow your site to access AJAX responses client side.
这篇关于跨域请求被阻止:同源策略不允许读取远程资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!