0

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!

Ray
  • 2,713
  • 3
  • 29
  • 61
Phil
  • 899
  • 1
  • 10
  • 20
  • Can you access the image link directly in the browser? http://localhost:3001/myproject/public/img-default.png – varoons May 24 '19 at 17:23
  • Possible duplicate of [How do I reference a local image in React?](https://stackoverflow.com/questions/39999367/how-do-i-reference-a-local-image-in-react) – Karin C May 24 '19 at 17:43
  • varoons.. nop, i cant – Phil May 24 '19 at 17:43

0 Answers0