I am trying to insert an image default inside my html using jQuery. I don't know why, but the path doesn't work. If the image-detail is 404 I have to use a default image. The image is called img-default.png and it is inside /public
this is the code:
fetch('url')
.then(function (response) {
return response.json();
}).then(function (data) {
const img_detail = data['img-detail']
if (data['img-detail'] == 404) {
console.log('error on load image')
const img_default = 'http://localhost:3001/myproject/public/img-default.png' // not work :(
//apply to div content
$('#content').css({ 'background-image': 'url(' + img_default + ')' });
} else {
$('#content').css({ 'background-image': 'url(' + img_detail + ')' });
}).catch(function () {
console.log("Error al traer la imagen");
});
Why doesn't it work? Thanks!