【发布时间】:2012-03-15 15:23:52
【问题描述】:
我刚刚在 iOS 上完成了一个 PhoneGap 应用程序,现在是时候将它移植到 WP7 上了。应用程序必须做的一件事是读取和解析 JSON 文件。
$.getJSON("xml-json/myfile.json",function(data){
// do cool things
});
但是当执行那行代码时,抛出了一些错误(没有办法调试所以我不知道错误是什么),并且执行不继续。知道该代码有什么问题吗? 该代码在 iOS 版本的 PhoneGap 上完美运行。
在中间窗口中抛出此错误:Log:"Wrapped XHR received Error from FileAPI :: [object Object]"
根据建议,我尝试使用 $.ajax 而不是 $.getJSON。该代码在浏览器和 iOS 上完美运行,但在 WP7 中却不行。像这样简单的东西不起作用:
函数 onDeviceReady() { document.getElementById("welcomeMsg").innerHTML += "Cordova 准备好了!version=" + window.device.cordova; console.log("onDeviceReady。您应该在 Visual Studio 的输出窗口中看到此消息。");
navigator.notification.alert("readingjson");
$.support.cors = true;
$.ajax({
url: "content2.json",
dataType: 'json',
context: document.body,
success: function (a, b, c) {
navigator.notification.alert("json readed");
}
});
navigator.notification.alert('yeah');
}
“readingjson”警报被触发,“是的”也被触发了,但是“json readed”一个ner被触发了......
谢谢!
【问题讨论】:
-
我已将此作为错误提交给 Cordova 开发人员