简体   繁体   English

segment.io javascript发布失败,出现CORS错误

[英]segment.io javascript publish fails with a CORS error

I'm encountering a cross origin resource sharing (CORS) error when I try to load a webpage with the sample "getting started" javascript code from the segment.io website. 当我尝试使用来自segment.io网站的示例“入门”javascript代码加载网页时,我遇到了跨源资源共享(CORS)错误。 Below is the html itself. 下面是html本身。 I haven't set any headers on my play 2.1.3 server that's vending this page, but I assume that's not necessary because other users have assured me they have run this with no problems.: 我没有在我的播放2.1.3服务器上设置任何标题出售此页面,但我认为没有必要,因为其他用户已经向我保证他们已经运行了这个没有问题:

<html>
<head>
<script type="text/javascript">
window.analytics=window.analytics||[],window.analytics.methods=["identify","group","track","page","pageview","alias","ready","on","once","off","trackLink","trackForm","trackClick","trackSubmit"],window.analytics.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),window.analytics.push(a),window.analytics}};for(var i=0;i<window.analytics.methods.length;i++){var key=window.analytics.methods[i];window.analytics[key]=window.analytics.factory(key)}window.analytics.load=function(t){if(!document.getElementById("analytics-js")){var a=document.createElement("script");a.type="text/javascript",a.id="analytics-js",a.async=!0,a.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.io/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n)}},window.analytics.SNIPPET_VERSION="2.0.9",
window.analytics.load("**my_key_here**");
window.analytics.page();
</script>
</head>
<body>
</body>
</html>

When I load this page with my browser, I see the following errors on the javascript console: 当我用浏览器加载此页面时,我在javascript控制台上看到以下错误:

[Error] Failed to load resource: Origin http://localhost:9000 is not allowed by Access-Control-Allow-Origin. (p, line 0)
[Error] XMLHttpRequest cannot load http://api.segment.io/v1/p. Origin http://localhost:9000 is not allowed by Access-Control-Allow-Origin. (localhost, line 0)

Any ideas? 有任何想法吗? Even on the segment.io site, there's no mention that CORS should be an issue just to publish events with the javascript client. 即使在segment.io网站上,也没有提到CORS应该只是用javascript客户端发布事件的问题。

It could be a browser extension that blocks tracking scripts. 它可能是阻止跟踪脚本的浏览器扩展。 Do you have one installed? 你有一个安装? For example, I was using Disconnect on Chrome and was experiencing a similar error until I whitelisted my site. 例如,我在Chrome上使用Disconnect ,并且在我将我的网站列入白名单之前遇到了类似的错误。

The error I was seeing was XMLHttpRequest cannot load http://api.segment.io/v1/i. The request was redirected to a URL ('about:blank') which has a disallowed scheme for cross-origin requests. 我看到的错误是XMLHttpRequest cannot load http://api.segment.io/v1/i. The request was redirected to a URL ('about:blank') which has a disallowed scheme for cross-origin requests. XMLHttpRequest cannot load http://api.segment.io/v1/i. The request was redirected to a URL ('about:blank') which has a disallowed scheme for cross-origin requests.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设置 Segment.io - Setting up Segment.io Segment.IO请求失败,状态为“已取消” - Segment.IO requests failing with Status of cancelled Segment.io的Analytics.js跟踪:传递对象? - Segment.io's Analytics.js Track: Pass an Object? 反应应用程序中的 risklySetInnerHTML 不适用于包含 Segment.io 标签 - dangerouslySetInnerHTML in react application not working for including Segment.io tags 如何将Segment.io服务器和客户端事件连接到同一个匿名用户? - How do I connect Segment.io server and client side events to the same anonymous user? 用于生产和非生产环境的Segment.io和mixpanel实现配置文件? - Segment.io and mixpanel implementation config file for production and non-production environments? 来自 segment.io 的 Track.form 片段取消了表单的重定向 - Track.form snippet from segment.io cancels redirect of the form 如何在淘汰定制绑定中使用segment.io的analytics.js - How to use segment.io's analytics.js in a knockout custom bindings 为什么Segment.io loader脚本将方法名称/ args推送到看似被覆盖的队列? - Why does the Segment.io loader script push method names/args onto a queue which seemingly gets overwritten? Javascript 中的套接字 IO 错误:“访问 XMLHttpRequest 已被 Z5A8FEFF0B4BDE3BEEC9D924 阻止” - Socket IO error in Javascript: “Access to XMLHttpRequest from origin 'null' has been blocked by CORS policy”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM