Ferex
Ferex

Reputation: 575

Phonegap/Cordova: get images from server

In my phonegap/cordova app I have a list of avatars. What's the best way to get this images on the app? Is it better to use the file transfer plugin to download the images? Or it is better to get them through an ajax call downloading them as binary? Something else? The images must be downloaded two times a day because users update them two times a day.

Upvotes: 2

Views: 1641

Answers (1)

Sport
Sport

Reputation: 8945

you can try like this

<body>
            <h1> Get Picture </h1>
            <button onclick="getPicture()">Get here</button>
            <div data-role="">
            <img id="productPic">
            </div>
            </body>

get the image from the server using 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);
        });
        }

look at the example http://javalearnersproblems.blogspot.in/2012/05/code-for-displaying-image-in-phonegap.html

Upvotes: 1

Related Questions