Bibek Aryal Bibek Aryal - 1 year ago 92
Javascript Question

How to display image from database instead of image path using jQuery

I want to display image from my database which stores the path to the image's location. Following code gives me the image path only in the output. What changes do I need to make in order for image to appear instead of image path?

GetBusinessCategoryList: function () {
var data = JSON2.stringify({
contentType: "application/json; charset=utf-8",
type: 'POST',
url: 'http://localhost:44719/Modules/BusinessCategoryView/Service/BusinessCategoryWebService.asmx/GetAllBusinessCategory',
dataType: 'json',
data: data,
success: function (result) {
var returnedData = result;
error: function (error) {
BindBusinessCategoryList: function (data) {
var cLst = data.d;
if (cLst.length > 0) {
headElements += '<table id="customerTable" cellspacing="0" cellpadding="0" >';
headElements += '<thead class="sfHeadingone">';
headElements += '<tr><th align="left">Category Image</th>';
headElements += '</thead>';
var i = 0;
if (i === 0) {
bodyElements += '<tbody>';
$.each(cLst, function (index, value) {

bodyElements += "<td>" + value.CategoryImage + "</td>";

Answer Source

Use img to display an image. Pass the image url to the src attribute of the img tag

bodyElements += "<td><img src='" + value.CategoryImage + "'></td>"; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download