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

2023-04-18前端开发问题
703

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

问题描述

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

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

The End

相关推荐

ajax请求获取json数据并处理的实例代码
ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc...
2024-11-22 前端开发问题
215

layui 单选框、复选框、下拉菜单不显示问题如何解决?
1. 如果是ajax嵌套了 页面, 请确保 只有最外层的页面引入了layui.css 和 layui.js ,内层页面 切记不要再次引入 2. 具体代码如下 layui.use(['form', 'upload'], function(){ var form = layui.form; form.render(); // 加入这一句});...
2024-11-09 前端开发问题
313

正则表达式([A-Za-z])为啥可以匹配字母加数字或特殊符号?
问题描述: 我需要在我的应用程序中验证一个文本字段。它既不能包含数字,也不能包含特殊字符,所以我尝试了这个正则表达式:/[a-zA-Z]/匹配,问题是,当我在字符串的中间或结尾放入一个数字或特殊字符时,这个正则表达式依然可以匹配通过。 解决办法: 你应...
2024-06-06 前端开发问题
165

Rails 3.1 ajax:成功处理
Rails 3.1 ajax:success handling(Rails 3.1 ajax:成功处理)...
2024-04-20 前端开发问题
11

CoffeeScript 总是以匿名函数返回
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)...
2024-04-20 前端开发问题
13

getFullYear 在一年的第一天返回前一年
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)...
2024-04-20 前端开发问题
6