我已经从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文件中...它的工作:(
答案 0 :(得分:0)
如果是iPhone应用程序,则需要编辑Cordova.plist,其中xcode位于Resources下。 编辑它(更好地通过xcode xml编辑器 - 即只需点击它)。 在Extenrnal Hosts下添加字符串项。 在价值上,设置您的网站,或*为任何外部网站。