How to render a remote hosted image in <img> tag

112 views
Skip to first unread message

rxraza

unread,
Apr 13, 2012, 4:42:17 AM4/13/12
to phonegap
How can we render the image using AJAX.

Assume you have an <img id="id1"/> tag declared in an HTML and using
AJAX filling out the src attribute like below

$("#id1").attr('src','http://www.some.com/img1.jpg');

I have a wildcard defined in the info.plist file but still I can't
render an image in the <img> tag

Shazron

unread,
Apr 13, 2012, 11:38:46 AM4/13/12
to phon...@googlegroups.com
Are you sure you are adding it in Cordova.plist, not Info.plist like
you mentioned?

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

Rizwan Raza

unread,
Apr 14, 2012, 1:36:38 AM4/14/12
to phon...@googlegroups.com
Sorry, it is defined in cordova.plist. Please understand that the the html file declares the img tag and src attribute is not populated until the button is clicked. When the button is clicked then an AJAX call is made that gets the url to the photo which is then associated to the src attribute using the following expression


$("#id1").attr('src','http://www.some.com/img1.jpg');



Noli Sicad

unread,
Apr 14, 2012, 2:05:28 AM4/14/12
to phon...@googlegroups.com
Ajax goes with PHP, sometimes with database.

Here is example AJAX, jQuery, MySQL(image is stored in database) and PHP
http://www.9lessons.info/2011/08/ajax-image-upload-without-refreshing.html

Noli

Rizwan Raza

unread,
Apr 14, 2012, 2:47:35 AM4/14/12
to phon...@googlegroups.com
I debugged it and when I printed what was assigned to src attribute, below is what I got

file:///Users/XXXX/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/ACB02AB6-A728-4B1C-9770-00BB89161364/ProjectB.app/www/XXX/'http://www.some.com/img.jpg

Is that even possible to dynamically assign src attribute of an image tag in an html page housed inside an phonegap (now Cordova) application using AJAX call?

Devgeeks

unread,
Apr 14, 2012, 2:53:15 AM4/14/12
to phon...@googlegroups.com
Instead, I create the img element when I am doing this, rather than just changing the src attribute.

<div id="yadda"><img id="id1"/></div>

$('#yadda').html('<img id="id1" src="http://www.some.com/img.jpg" />');

Perhaps this could be a solution...

Rizwan Raza

unread,
Apr 14, 2012, 3:04:34 AM4/14/12
to phon...@googlegroups.com
Yes! that did work. Thanks a lot.

Reply all
Reply to author
Forward
0 new messages