blackPanther's avatar

How to append an image using jquery to Div element through ajax

I have an ajax response where the object is as follows

https://drive.google.com/open?id=0B4WeiY_22ZtkMnNDMkQ1cUQ3SVE

and I want to append the image to a div

$('#DisplayImage').empty().append('<img (src)="response.unit_plan_images.UnitImage" height="64px" width="64px">'); // not sure if this is correct

can you please assist me

0 likes
2 replies
Cronix's avatar
Cronix
Best Answer
Level 67

I think it's because you have the response.unit_plan_images.UnitImage within the quotes of the img src, so it thinks that string is literally the url of the image instead of the data from your json object. Break out of the quote and concatenate.

'<img src="'+response.unit_plan_images.UnitImage+'" height="64px" width="64px">'

Also not sure why you had parenthesis around src?

blackPanther's avatar
'<img src="images/'+response[0].unit_plan_images.UnitImage+'" height="64px" width="64px">'

I had src put in brackets because laracast was displaying the image in the tag for some reason. Thanks though

Please or to participate in this conversation.