我正在尝试使用 phonegap 和 jquery 来执行以下操作。使用 $.ajax() 加载图像,将其存储在 localStorage 中,并在 html 页面中显示。
$.ajax({
 type: 'GET',
 url: uri,
 success: function(data, textStatus, jqXHR) {
  if (textStatus === "notmodified") {
    console.log("NOT modified.");
  } else {
    console.log("download complete. Total Bytes: " + data.length);
    window.localStorage.setItem(fileName,btoa(encodeURIComponent(data)));
  }
 }
})
然后稍后:
$('#info img').each( function() {
 var fileName = this.src;
 var pos = fileName.lastIndexOf('/');
 if(pos >= 0)
  fileName = fileName.substring(pos + 1);
 //Check for image
 var pos = fileName.lastIndexOf('.');
 var ext;
 if(pos >= 0)
   ext = fileName.substring(pos + 1);
 if(fileName in filesSynchronized)
  this.src = 'data:image/' + ext +';base64,' + window.localStorage[fileName];
但图像已损坏。我究竟做错了什么?ajax 不返回图像的字节数组吗?btoa 不能正常工作吗?