[英]Origin null is not allowed by Access-Control-Allow-Origin (get XML from android)
I've researched about this problem. 我已经研究了这个问题。
Everywhere people get this error because of reading local file from localhost. 人们到处都会收到此错误,因为从本地主机读取本地文件。 Also almost everywhere people need a json.
几乎每个人都需要json。
In my case i want to get this xml file from this site from android (WebView). 以我为例,我想从android(WebView)网站上获取此 xml文件。 So can anybody explain what's wrong?
有人能解释什么地方吗? What should I do to get it?
我应该怎么做才能得到它?
Here's my code: 这是我的代码:
$.get('http://www.revotech.am/smarthome/app/xml/config.xml', function(xmlData)
{
...
}
I assue you are using Android version JELLY_BEAN or above and the javascript is running in the context of a file schema - If YES then do the following. 我保证您使用的是Android版本JELLY_BEAN或更高版本,并且javascript在文件模式的上下文中运行-如果是,请执行以下操作。
webView.getSettings().setAllowFileAccessFromFileURLs(true); webView.getSettings()。setAllowFileAccessFromFileURLs(true);
From the Android documentation: 从Android文档中:
Sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from any origin.
设置是否应允许在文件方案URL上下文中运行的JavaScript从任何来源访问内容。 This includes access to content from other file scheme URLs.
这包括从其他文件方案URL访问内容。 See setAllowFileAccessFromFileURLs(boolean).
请参见setAllowFileAccessFromFileURLs(boolean)。 To enable the most restrictive, and therefore secure policy, this setting should be disabled.
要启用限制性最强,因此最安全的策略,应禁用此设置。
The default value is true for API level ICE_CREAM_SANDWICH_MR1 and below, and false for API level JELLY_BEAN and above.
对于API级ICE_CREAM_SANDWICH_MR1及以下,默认值为true;对于API级JELLY_BEAN及以上,默认值为false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.