显示Javascript“相同来源政策”违规 [英] Display Javascript "same origin policy" violations

查看:187
本文介绍了显示Javascript“相同来源政策”违规的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个运行一个简单的HTTP服务器和一个WebView的移动应用程序。 WebView显示一个外部网站,通过javascript(GET)访问服务器。不幸的是,这不起作用,我认为这是由于相同的起源政策,但控制台不显示任何错误。我之前有一个类似的错误,要求我在服务器端定义Access-Control-Allow-Origin:*。这个错误已经花费了一段时间,因为没有错误消息(FirebugNet选项卡显示一个完整的GET请求与空的响应数据)。现在,我假定在外部脚本中违反了相同的源策略,但是由于缺少错误消息,很难说清楚。我看到的唯一的提示是在FirebugNet选项卡中显示永不完成的连接。我检查了发送到本地主机的软件包,但是甚至没有连接尝试=>因此,我认为浏览器正在把它保留。



如何显示Javascript Firefox(3.6.20和Chrome)引发了一个源代码策略违例错误(ext:Firebug,Webdeveloper)?

解决方案

XMLHttpRequest错误跨域违规。这些错误可以通过 try {...} catch(ignore){} 块来消除。如果您知道请求的实际路径,您可以在Firebug的Net选项卡中进行检查,则所有请求(甚至被同源策略拒绝的请求)将显示在所有部分中,在XHR被同源国政策否认的不是。


I'm developing a mobile app which runs a simple HTTP server and a WebView. The WebView displays an external website which should access the server via javascript (GET). Unfortunately this doesn't work and I assume it's due to the same origin policy but the console doesn't show any errors. I had a similar error before which required me to define "Access-Control-Allow-Origin: *" on the server side. This error already took a while to find because there were no error messages (Firebug "Net" tab showed a completed GET request with empty "response" data). Now I assume a same origin policy violation in the external script, but it's hard to tell because of the missing error messages. The only "hint" I see is in Firebug "Net" tab, showing a connection which "never completes". I checked the packages sent to localhost but there wasn't even a connection attempt => thus I assume the browser is holding it back.

How do I display Javascript "same origin policy" violation errors in Firefox (ext: Firebug, Webdeveloper)?

解决方案

Firefox(3.6.20 and Chrome) throws an error on XMLHttpRequest cross domain violations. These errors can being silenced by try{...} catch(ignore){} blocks. If you know the actual path of the request you can check in the Firebug's "Net" tab, all the requests(even those denied by "same origin policy") show in the "All" section, and in the "XHR" section those denied by "same origin policy" don't.

这篇关于显示Javascript“相同来源政策”违规的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆