【发布时间】:2015-10-31 10:56:30
【问题描述】:
我在 Jquery mobile 1.4.5 上有一个项目,我从本地 JSON 数据加载数据并将它们解析为列表。当我在 Firefox 中对其进行测试时,它工作正常,列表已填充,一切正常,但是当我在cordova 和 android 中编译它时,在移动设备上未填充来自 json 的列表。我将 data.json 文件保存在 www 项目文件的根文件夹中。可能是什么问题?
$.getJSON('data.json', function(data) {
var output="<ul>";
for (var i in data.sometext) {
output+="<li " +
"blah blah blah"
"</li>" ;
}
output+="</ul>";
document.getElementById("placeholder").innerHTML=output;
});
在我的科尔多瓦配置文件中:
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" version="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<preference name="orientation" value="portrait" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
【问题讨论】:
-
尝试用获取 json 的 url 替换 data.json
-
但是我想构建一个离线应用,我想将json数据保存在用户设备中。
-
phonegaptutorial.com/… 看看这个,可能会有帮助
-
ajax 失败时会出现什么错误?
-
在 Firefox 中没有错误,Json 文件加载正常,在 chrome 中我得到:XMLHttpRequest cannot load file:///C:/Users............/data.json .跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource。在设备中我怎么能得到这些错误?在 Chrome 中,我对跨源错误并不感到惊讶,因为我认为使用 dordova 和
构建应用程序可以解决这个问题....
标签: android jquery json cordova jquery-mobile