Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys, i need display images of product in array but I can't get photo path or something else. I don't know what is wrong.................

JavaScript
success: function (result) {

                 jQuery.each(result, function (key, value) {
                     var image = document.createElement("img");
                     image.src = "~media/photos/" + value.imagePath + "";
                     image.height = "250";
                     image.width = "250";
                     image.alt = value.imagePath;
                     $("#productImage").append(image);

                 });

             }


this is result: href="https://www.linkpicture.com/q/yt_1.jpg">[^]

What I have tried:

......................................................
Posted
Updated 15-Nov-20 21:28pm
Comments
F-ES Sitecore 15-Nov-20 6:40am    
Try

image.src = "/media/photos/" + value.imagePath + "";

1 solution

You've tagged this question as C#, but only posted Javascript code.

Assuming you're using ASP.NET, and are trying to use an app-relative path[^], that only works in server-side code. For Javascript, you need to use either a relative path (../path/to/file.ext), a site-relative path (/app/path/to/file.ext) or an absolute path (https://yoursite.tld/app/path/to/file.ext).

You should update your server-side code to resolve the app-relative path and return that instead of simply returning the file name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900