|
做的小例子,准备读取远程直链的库到数据直接把test.db丢到项目里,可以调试,也可以在征集访问但是读取远程数据的时候貌似就代码会报错跨域错误
- var url ="http://d.139.sh/115899893/test.db";
- var xhr = new XMLHttpRequest();
- var db =null;//
- xhr.open('GET', url, true);
- xhr.responseType = 'arraybuffer';
- xhr.onload = function(e) {
- var uInt8Array = new Uint8Array(this.response);
- db = new SQL.Database(uInt8Array);
- }
- xhr.send();
复制代码
然后准备使用$cordovaFileTransfer把文件下载到本地试试,这时候模拟器调试会找不到cordova.file.对象,就在真机上跑,
真机上可以获取cordova.file.但是但是下载到本地时进了err,
错误信息http_status是401,貌似也是和跨域有关的,不知道怎么弄了
- var url = "http://cdn.wall-pix.net/albums/art-space/00030109.jpg";
- var targetPath = cordova.file.externalDataDirectory + "testImage.png";
- var trustHosts = true;
- var options = {};
- $cordovaFileTransfer.download(url, targetPath, options, trustHosts)
- .then(function(result) {
- // Success!
- }, function(err) {
- // Error
- var temp="";
- temp+="&code="+err.code;
- temp+="&source="+err.source;
- temp+="&target="+err.target;
- temp+="&http_status="+err.http_status;
- temp+="&body="+err.body;
- temp+="&exception="+err.exception;
- $rootScope.err="&2err==="+temp;
-
- }, function (progress) {
- $timeout(function () {
- $scope.downloadProgress = (progress.loaded / progress.total) * 100;
- });
- });
复制代码
|
|