Snehal Snehal - 8 months ago 30
jQuery Question

Display image from its path stored in database

I want to display an image from the JSON object and the path of the image stored in MySQL database.

I have user table which contains:

  • userid

  • username

  • user_img_path

  • user_address

Now, I'm firing a query using PHP like:

SELECT `user_id`, `username`,`user_img_path` FROM `users`

And I store the output in an array
and encode this array into JSON as


and I call this PHP file in my jQuery's
call and get JSON output. I can display other info properly, but the problem is that I couldn't display the image in HTML using jQuery

function callAjax1()
url: 'userApi.php',
data: "",
dataType: 'json',
var user_id=rows[i].user_id;
var user_name=rows[i].user_name;
var user_img_path=rows[i].user_img_path;
$("#poll_left_body").append('<a href="#"> <img src=\https://url/"'+user_img_path+'<label id="user_name" rel="tooltip" title=" Edward 11,356" style="color:black;">'+user_name+'</label></a><a href="/twitter/bootstrap/network" class="social-count">11,356</a>');

srs srs
Answer Source

try to put user_img_path into variable and use javascript

var img = document.createElement("img");
img.src = user_img_path;  
var body = document.body;  // use element where you want to display image
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download