tôi đã cố gắng writing/reading
một tập tin trong phonegap+android
, đây là thiết lập:Viết và tập đọc trong PhoneGap
$(document).ready(function() {
document.addEventListener("deviceready", deviceready, true);
$(document).bind("deviceready", function(){
//writeFile();
//readFile();
});
});
function deviceready() {
writeFile();
readFile();
}
// This is just to do this.
function readFile() {
var d = navigator.file.read('/sdcard/foo.xml', success(), fail());
console.warn(d);
}
function writeFile() {
navigator.file.write('/sdcard/foo.xml', "This is a test of writing to a file",
success(), fail());
}
Nhưng trên giả lập cho Android 2.2, tôi nhận được thông báo lỗi sau:
08-06 14:21:29.428: INFO/Web Console(936): Error in success callback: Network Status1 = TypeError: Result of expression 'navigator.file' [undefined] is not an object. at file:///android_asset/www/phonegap.0.9.6.js:649
Điều gì có thể bị thiếu và những gì có thể được thử?
có thể là bạn đang sử dụng thành công() thay vì thành công trong cuộc gọi của bạn trở lại cùng đi cho Fail() nên không –