Good day. I made a page on which I display a picture from the img src tag "", but it is not displayed until you open the browser from scratch. Here is its code:

<html> <head> <script language="JavaScript" type="text/javascript"> function getCustomer(){ var xhr = new XMLHttpRequest(); xhr.open("GET", "/customer/"+customerLogin,false); xhr.send(null); var data = JSON.parse(xhr.responseText); var customerPhoto = data.photo.linkLocation; var customer = data.customers[0]; customerLogin = customer.login; document.getElementById("customerLogin").value = customerLogin; document.getElementById("customerPassword").value = customer.password; document.getElementById("customerName").value = customer.name; document.getElementById("customerSurname").value = customer.surname; document.getElementById("customerPhone").value = customer.phone; var img = document.getElementById("customerPhoto"); alert(customerPhoto); img.setAttribute("src",customerPhoto); } </script> </head> <body class="profile" onload="pageReady();getCustomer();"> <div class="photo"> <br/><img id="customerPhoto" width="500" height="500"><br/></div> </div> </body> </html> 

Excess did not add. When you load the page, the alert displays the correct path to the image, but it only loads when you re-open the browser page or reload the pages multiple times. I understand this is not enough (learning), it is not connected with the cache, by chance? Thank.

  • Worth seeing console errors when not loading - Grundy
  • Place the script after the picture tag at the bottom of the page. - Ella Svetlaya
  • @EllaSvetlaya, how will this help in this case? - Grundy
  • @EllaSvetlaya did not help ... - Nikolai Egorov
  • one
    so it seems I figured it out ... I have a connection with Restcontroller Java via Tomcat .... An error, it seems, when accessing resources ... - Nikolay Egorov

0