Phonegap/Cordova:从服务器获取图像
问题描述:
在我的phonegap/cordova应用程序中,我有一个化身列表。 在应用程序上获取这些图像的最佳方式是什么? 使用文件传输插件下载图像更好吗?或者最好让他们通过ajax调用下载它们作为二进制文件?还有别的吗? 图像必须每天下载两次,因为用户每天更新它们两次。Phonegap/Cordova:从服务器获取图像
答
你可以尝试这样的
<body>
<h1> Get Picture </h1>
<button onclick="getPicture()">Get here</button>
<div data-role="">
<img id="productPic">
</div>
</body>
使用JSON服务器获取图像。
function getPicture()
{
$
.getJSON("http://yoururlhere/getImage.action",
{}, function(data) {
processPictureData(data);
});
}
function processPictureData(data)
{
$.each(data.PICTURE, function(i, product) {
$('#productPic').attr('src', product.LOCAT);
});
}
看看例子http://javalearnersproblems.blogspot.in/2012/05/code-for-displaying-image-in-phonegap.html