【发布时间】:2016-02-04 13:01:55
【问题描述】:
我有一个运行良好的cordova 项目,但是由于我已经更新到cordova 6.0 和新的webview,我收到了这个错误:
XMLHttpRequest cannot load file:///Users/adrian/Library/Developer/CoreSimulator/Devices/3ACC077E-9068-4352-A28B-4BD13124BE5B/data/Containers/Bundle/Application/A387F0D2-9445-4E1F-BF85-7AAF68CBA973/Vivre.app/www/images/icons/dest/index.html?_=1454590513181. Cross origin requests are only supported for HTTP.
jQuery 代码:
$.ajax({
dataType: 'html',
crossDomain: true,
url: "./images/icons/dest/index.html",
beforeSend: false,
cache: false
}).done(function(data){
$( "#js-svg-inline" ).append(data).hide();
});
【问题讨论】:
-
尝试使用绝对网址:
http://example.com/path/to/your/index.html -
@WayNe 这是科尔多瓦应用程序中的本地文件
-
你需要使用localhost,即使它的本地文件因为跨域策略
-
好的,经过一些研究,看起来像cordova treets 像网络服务器的根目录一样的 www 目录(请注意错误的方向......)。你在 config.xml 中设置了
<access origin="*" />吗? -
这是 WKWebView 上的一个已知问题,除非您使用本地 Web 服务器,否则您无法进行本地 ajax 调用
标签: javascript jquery ios cordova