跨域请求被阻止:同源策略不允许读取远程资源

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at(跨域请求被阻止:同源策略不允许读取远程资源)
本文介绍了跨域请求被阻止:同源策略不允许读取远程资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在我的网站中使用 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.

这篇关于跨域请求被阻止:同源策略不允许读取远程资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)
WebKit quot;Refused to set unsafe header #39;content-length#39;quot;(WebKit “拒绝设置不安全的标头‘内容长度’)
$.ajax call working fine in IE8 and Doesn#39;t work in firefox and chrome browsers($.ajax 调用在 IE8 中运行良好,但在 Firefox 和 chrome 浏览器中不起作用)