Добрый день. Сделал страничку, на которой отображаю картинку из тэга img src"", но она не отображается до того, как не откроешь браузер с нуля. Вот ее код:
<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>
Лишнее не добавлял. При загрузке страницы alert выводит правильный путь к картинке, но загружается она только при повторном открытии страницы браузера или многократных перезагрузок страниц. Понимаю в этом пока маловато (учусь), это не с кэшем связано, случайно? Спасибо.
Сборка персонального компьютера от Artline: умный выбор для современных пользователей