Javascript PhoneGap+;AngularJS无法读取刚创建的文件

Javascript PhoneGap+;AngularJS无法读取刚创建的文件,javascript,angularjs,cordova,Javascript,Angularjs,Cordova,我在PhoneGap 3.5.0项目中使用AngularJS,我在XCode的iOS 5和6上使用它 我尝试读取我以前编写的文件。但是我总是有一个空字符串,而不是response的值,它是一个JSON $http.get(API + '/content') .success(function (response) { // response is a JSON console.log(response); window.requestFileSystem(LocalFi

我在PhoneGap 3.5.0项目中使用AngularJS,我在XCode的iOS 5和6上使用它

我尝试读取我以前编写的文件。但是我总是有一个空字符串,而不是
response
的值,它是一个JSON

$http.get(API + '/content')
.success(function (response) {
    // response is a JSON
    console.log(response);

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (filesystem) {
        filesystem.root.getDirectory('json', {create: true}, function (dirEntry) {
            dirEntry.getFile('contents.json', {create: true, exclusive: false}, function (fileEntry) {
                fileEntry.createWriter(function (fileWriter) {
                    fileWriter.onwriteend = function (e) {
                        // this is not working...
                        fileEntry.file(function (file) {
                            var reader = new FileReader();

                            reader.onloadend = function (e) {
                                // e.target.result is an empty string (!?)
                                console.log(e.target.result, typeof e.target.result);
                            };

                            reader.readAsText(file);
                        });
                    };

                    fileWriter.write(response);
                });
            });
        });
    });

});

我有一个与照片一起使用的工作版本:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
                fileSystem.root.getDirectory("photos", {create: true, exclusive: false}, function(dir) {
                    dir.getFile("photo_"+Date.now()+".jpg", {create: true, exclusive: false}, function(fileEntry){
                        fileEntry.createWriter(function(writer){
                            writer.onwriteend = function (evt) {
                                scope.processPhoto(fileEntry.toURL(), $(element).index());
                            };
                            writer.write(element.find('input')[0].files[0]);
                        }, fail);
                    }, fail);
                }, fail);
            }, fail);
处理fail的函数是

function fail(error) {
            console.log(error.code);
        }
我看不出为什么我的工作和你的不工作有太大的区别,但是试着使用fail函数来深入到可能的错误代码,并导致你的情况发生特殊的变化