i try store locally , display image retrieve using ajax call, in cordova. here source:
<!doctype html> <!-- licensed apache software foundation (asf) under 1 or more contributor license agreements. see notice file distributed work additional information regarding copyright ownership. asf licenses file under apache license, version 2.0 (the "license"); may not use file except in compliance license. may obtain copy of license @ http://www.apache.org/licenses/license-2.0 unless required applicable law or agreed in writing, software distributed under license distributed on "as is" basis, without warranties or conditions of kind, either express or implied. see license specific language governing permissions , limitations under 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 device</p> <p class="event received">device 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>
problem is, seems success function of first window.requestfilesystem call (commented "here") never called. neither error function called. "dans doprocess" alert displayed, , nothing happens anymore. i'm testing xcode , ios simulator. idea?
Comments
Post a Comment