I'm trying to display a raw image which has been formatted to base64 into an img element with javascript. I already have my base64 but cannot make it displaying as raw image, what is wrong with the code?
here is the code.
$.each(post.JobPictures, function (i, pictures) {
if (pictures != null) {
var decodedString = atob(pictures.JobImageContentBytes)
var img = new Image();
img.src = ("data:image/jpg;base64,"+ decodedString);
`<div class="separate-pic">
<img class="posted-pic" src="`+img+`" alt="" />
</div>`
}
})
UPDATE THIS IS USING MAP NOW, BUT IT DOES NOT GO IN AT ALL
$.ajax({
url: '@Url.Action("SearchByCategory", "AllJobs")',
type: 'GET',
contentType: 'JSON',
data: { category: categoryId },
success: function (posts) {
$(".job-container").html("");
//$(".job-container").load(" .job-container");
$.each(posts.FindJobs, function (i, post) {
var newdate = new Date(post.PostedDate + 'Z');
var day = newdate.getDate();
$(".job-container").append(`
<li class="separate-job" id="All-Jobs-Id" value="` + post.jobId + `">
<div class="content-li-All-Jobs">
<h2 class="content-li-All-headline" id="headline-for-Update">`+ post.Headline + `</h2>
<a class="btn btn-success bid-for-job" value="`+ post.jobId + `" href="#">Bid now</a>
<div class="user">
<blockquote class="blockquote">
<p class="mb-0">
<div class="about-job">`+ post.About + `</div>
</p>
<div class="blockquote-footer">
<cite>-`+ post.Username + `</cite>
</div>
</blockquote>
</div>
<div class="pictures-li">
`+ $.map(post.jobPictures, function (i, pictures) {
if (pictures != null) {
var decodedString = atob(pictures.JobImageContentBytes)
return `<div class="separate-pic">
<img class="posted-pic" src="data:image/jpg;base64,${decodedString}" alt="" />
</div>`;
}
}).join("") + `
</div>
<div class="job-date-li">
Posted `+ newdate.getDate() + ` ` + newdate.getMonth() + ` ` + newdate.getFullYear() +
`
</div>
<div class="-job-town">Area | <span class="city">`+ post.JobCity+`</span></div>
</div>
</li>
`)
});
}
});
This is my entire ajax call which I make to a controller in order to get all jobs which are in certain category and create those divs and assign the relevant data to them
here is the image that shows that the object/arrays are not empty


contentType: 'JSON',is wrong, it should bedataType: 'json'