【问题标题】:What is the best way to diplay images remotely from server in a PhoneGap app在 PhoneGap 应用程序中从服务器远程显示图像的最佳方式是什么
【发布时间】:2013-07-02 11:38:32
【问题描述】:

我正在尝试使用 phoneGap 以及 jquery(mobile) 和 PHP 在应用程序中显示来自远程服务器的图像。

我从文档中读到这个函数可以完成这项工作:

文件传输

这里:http://docs.phonegap.com/en/1.6.0/cordova_file_file.md.html

 // !! Assumes variable url contains a valid URI to a file on a server and filePath is a valid path on the device

var fileTransfer = new FileTransfer();

fileTransfer.download(
    url,
    filePath,
    function(entry) {
        console.log("download complete: " + entry.fullPath);
    },
    function(error) {
        console.log("download error source " + error.source);
        console.log("download error target " + error.target);
        console.log("upload error code" + error.code);
    }
);

我的问题是我不知道到达我的应用程序根目录的文件路径应该是什么? 主要问题(这就是我创建这篇文章的原因)是我从文档中读到

也可以从远程下载文件并将其保存在设备上(仅限 iOS 和 Android)。

这对我来说是个问题..

那么我该怎么办,我可以将服务器中的图像 url 提供给 phonegap 应用程序中图像的 src 吗?这行得通吗?

谢谢

【问题讨论】:

    标签: javascript jquery ajax cordova


    【解决方案1】:

    我通常使用 html 标签在 phonegap 应用程序中显示来自远程服务器的图像。

    【讨论】:

    • 是的,但是图像来自哪里,来源是什么?在应用内还是远程在服务器上?
    • 远程服务器可以托管图像,例如您可以尝试以下 标签从远程服务器加载图像placeholder.it placehold.it/350x150">
    • 或者,您可以将图像打包为带有 phonegap 应用程序的目录中的资产,当最终用户安装您的 phonegap 应用程序时,图像将部署在客户端上。可以使用 html 标记中的相对 url 访问这些资产。例如,您使用 phonegap 应用程序将图像打包到“images”文件夹中,您可以使用以下语法在 html 标记中引用它们:
    • 这些是个人资料图片,因此它会根据您正在查看的用户个人资料通过 AJAX 查询动态检索。下载应用程序时无法安装。它必须从服务器动态检索
    • 您可以将图像托管在远程服务器上,并构造具有 src 属性的 html 标记作为 AJAX 调用成功时远程托管图像的完整地址。
    猜你喜欢
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 2015-01-08
    相关资源
    最近更新 更多