Javascript window.requestFileSystem不';我不能在科尔多瓦工作

Javascript window.requestFileSystem不';我不能在科尔多瓦工作,javascript,cordova,html5-filesystem,Javascript,Cordova,Html5 Filesystem,我尝试在本地存储并在Cordova中显示使用Ajax调用检索到的图像。以下是我的消息来源: <!DOCTYPE html> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional

我尝试在本地存储并在Cordova中显示使用Ajax调用检索到的图像。以下是我的消息来源:

<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />

        <title>Test requestFileSystem</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>

    </body>
</html>
<script>
    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;

    function onError(e) {
        console.log('Error', e);
    }

    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://upload.wikimedia.org/wikipedia/fr/2/26/10_francs_Mathieu_1987_F365-28_revers.jpg', true);
    xhr.responseType = 'blob';

    window.onload = function() {
        document.addEventListener("deviceready", start, false);
    }

    function start() {
        alert("dans start : deviceready fired");
        xhr.send();
    }

    xhr.onload = function(e) {
        alert("xhr.onload");
        doProcess();
    }

    function doProcess() {
        alert('dans doProcess');
        window.requestFileSystem(PERSISTENT, 1024 * 1024, function(fs) { // here
            alert('dans requestFileSystem 1 success');
            fs.root.getFile('image.jpg', {create: true}, function(fileEntry) {
                alert('dans getFile 1 success');
                fileEntry.createWriter(function(writer) {
                    alert('dans createWriter');
                    writer.onwrite = function(e) {};
                    writer.onerror = function(e) {};

                    var blob = new Blob([xhr.response], {type: 'image/jpeg'});

                    writer.write(blob);

                }, function(e) {
                    console.log('Error', e);
                });
            }, function(e) {
                console.log('Error', e);
            });
        }, function(e) {
            alert('error');
            console.log('Error', e);
        });

        window.requestFileSystem(PERSISTENT, 1024 * 1024, function(fs) {
            alert('dans reqestFileSystem 2 success');
            fs.root.getFile('image.jpg', {create: false}, function(fileEntry) {
                fileEntry.file(function(file) {
                    alert('dans file');
                    var reader = new FileReader();
                    reader.onloadend = function(event) {
                        var img = document.createElement("img");
                        img.src = event.target.result;

                        document.body.parentNode.insertBefore(img, document.body.nextSibling);
                    };
                    reader.readAsDataURL(file);
                }, function(e) {
                    console.log('Error', e);
                });
            }, function(e) {
                console.log('Error', e);
            });
        }, function(e) {
            console.log('Error', e);
        });

    };

    //xhr.send();</script>

测试请求文件系统
阿帕奇科尔多瓦酒店
连接到设备

设备已准备就绪

app.initialize(); window.requestFileSystem=window.requestFileSystem | | window.webkitRequestFileSystem; 函数onError(e){ console.log('Error',e); } var xhr=new XMLHttpRequest(); xhr.open('GET','http://upload.wikimedia.org/wikipedia/fr/2/26/10_francs_Mathieu_1987_F365-28_revers.jpg",对),; xhr.responseType='blob'; window.onload=函数(){ 文件。添加的监听器(“DeviceRady”,开始,错误); } 函数start(){ 警报(“dans启动:设备已启动”); xhr.send(); } xhr.onload=函数(e){ 警报(“xhr.onload”); doProcess(); } 函数doProcess(){ 警报(“dans doProcess”); requestFileSystem(持久,1024*1024,函数(fs){//此处 警报(“dans请求文件系统1成功”); getFile('image.jpg',{create:true},函数(fileEntry){ 警报(“dans获取文件1成功”); createWriter(函数(writer){ 警报(“dans createWriter”); writer.onwrite=函数(e){}; writer.onerror=函数(e){}; var blob=new blob([xhr.response],{type:'image/jpeg'}); writer.write(blob); },功能(e){ console.log('Error',e); }); },功能(e){ console.log('Error',e); }); },功能(e){ 警报(“错误”); console.log('Error',e); }); requestFileSystem(持久,1024*1024,函数(fs){ 警报(“dans请求文件系统2成功”); getFile('image.jpg',{create:false},函数(fileEntry){ fileEntry.file(函数(文件){ 警报(“dans文件”); var reader=new FileReader(); reader.onloadend=函数(事件){ var img=document.createElement(“img”); img.src=event.target.result; document.body.parentNode.insertBefore(img,document.body.nextSibling); }; reader.readAsDataURL(文件); },功能(e){ console.log('Error',e); }); },功能(e){ console.log('Error',e); }); },功能(e){ console.log('Error',e); }); }; //xhr.send();

问题是,似乎从未调用第一个window.requestFileSystem调用(注释为“here”)的success函数。错误函数也没有被调用。显示我的“dans doProcess”警报,然后不再发生任何事情。我正在用XCode和iOS模拟器进行测试。有什么想法吗?

hi使用0代替1024*1024并检查我不确定只需尝试@TrarothIt不会改变任何东西。在doProcess中尝试并捕获代码,您可能会得到有用的信息。同时检查您是否允许应用程序访问文件系统。您是否解决了此问题????