I create a picture like this:

function(file,dataUrl){ var date = new Date(); var path = window.location.host+'/frontend/web/image/page/'+date.getFullYear()+'/'+(1+date.getMonth())+'/'+file.name; var img = document.createElement('img'); img.src = path; document.getElementById('forIMG').appendChild(img);} 

But it is not displayed on the page, or rather displayed like this:

no picture

The address I checked the picture is.

I am trying to get the data for the image like this:

  $("#forIMG").on('click','img',function () { console.log($(this)); }); 

Got nothing, what's wrong?

  • one
    I checked the address is a picture - it means the address is not the same. Look at the browser console, there should be an error that he could not upload a picture to such an address. That's it there and not. - Grundy
  • console.log (path); make the crap most likely with the way - Lieutenant Jim Dangle
  • @Grundy if the address specified in src is entered in the address bar of the browser, the picture will be displayed - Sergalas
  • @FrankSinatra I just answered, but even this does not give an answer why the second code does not work. - Sergalas
  • just make log ($ ("# forIMG")) and you don’t need to click everything or something else, it will show you the object - Lieutenant Jim Dangle

1 answer 1

window.location.host does not contain a protocol. For example, window.location.host on the current site is http://ru.stackoverflow.com
It will not be possible to upload a picture for example from http://ru.stackoverflow.com /image/image.png , you need to specify the protocol over which the download should take place it was better not to specify window.location.host at all on the way

  • The idea is correct, but it is written incorrectly ... - Qwertiy
  • Why do we need window.location.host at all? if the picture is set to the path starting from / , then by default it will be addressed to the current host - Mike
  • @Mike well, here it is where the dog rummaged, I asked why such a mistake - Sergalas
  • @Qwertiy and what is wrong? - Sergalas
  • At least, an example. And then generally somehow dullly written. - Qwertiy