我已经从 Phonegap 1.5.0 更新到 2.0.0,面临下载问题。
这是我的下载功能:
function download(){
var ecodedurl = "http://finance.yahoo.com/d/quotes.csv?s=^NSEI+^NSEBANK&f=pl1";
var remoteFile = encodeURI(ecodedurl);
var localFileName = "temp.txt";
var attachmentFileName = localFileName;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getDirectory("Temp", {create: true, exclusive: false}, function(directoryEntry) {
directoryEntry.getFile(localFileName, {create: true, exclusive: false}, function(fileEntry) {
var localPath = fileEntry.fullPath;
if (device.platform === "Android" && localPath.indexOf("file://") === 0) {
localPath = localPath.substring(7);
}
var ft = new FileTransfer();
ft.download(remoteFile,
localPath, function(entry) {
attachmentFileEntry = entry;
loadFileData(attachmentFileEntry);
}, fail);
}, fail);
}, fail);
}, fail);
function fail(error) {
//console.log(error.code);
//alert("Error occured while downloading the attachment");
navigator.notification.alert('Error occured while downloading the attachment. Please try again', alertConfirm);
}
}
}
function loadFileData(allText) {
console.log("loadFileData method:"+allText);
console.log("allText URL:"+allText.toURL());
var fileURL = allText.toURL().substring(7);
console.log("URL:"+fileURL);
$.ajax({
type: "GET",
url: fileURL,
dataType: "text",
success: function(data) {
console.log("file loaded");
processData(data);}
});
获取文件传输错误:源 URL 不在白名单中:http: //finance.yahoo.com/d/quotes.csv? s= ^NSEI+^NSEBANK&f=pl1
已尝试将其包含在 phonegap.xml 文件中...它可以正常工作:(