2

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 () {
            debugger;               
            var data = JSON2.stringify({                        
                });
            $.ajax(
                {
                    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) {
                        alert("ok");
                        var returnedData = result;
                        BusinessManagement.BindBusinessCategoryList(returnedData);
                    },
                    error: function (error) {
                        alert("error");
                    }
                });            
        },
        BindBusinessCategoryList: function (data) {
            debugger;
            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>';
                $('#tblGrid').html(headElements);
                var i = 0;
                if (i === 0) {
                    bodyElements += '<tbody>';
                }
                $.each(cLst, function (index, value) {

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

1 Answer 1

2

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>"; 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. This partially solved my problem as the console still says "Failed to load resource" but I should be able to figure that one out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.