-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplain_with_ajax_load.html
47 lines (45 loc) · 2.16 KB
/
plain_with_ajax_load.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>
Plain HTML page with AJAX-loaded image
</title>
<script type="text/javascript">
function loadImg() {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
console.log('readyState 4');
if (xmlhttp.status = 200) {
var img = document.createElement('img');
img.src = window.URL.createObjectURL(this.response);
img.onload = function() {
window.URL.revokeObjectURL(this.src);
}
document.body.appendChild(img);
} else if (xmlhttp.status = 400) {
alert("Oh no, there was an error 400");
} else {
alert("Something else other than 200 or 400 returned")
}
}
}
xmlhttp.open("GET", "lenna.png", true);
xmlhttp.responseType = "blob";
xmlhttp.send();
}
document.addEventListener("DOMContentLoaded", function(event) {
loadImg();
});
</script>
</head>
<body>
<h1>Plain HTML page with AJAX-loaded image</h1>
<p>Bacon ipsum dolor amet lorem landjaeger corned beef in venison reprehenderit picanha ipsum alcatra shoulder strip steak chicken. Salami eiusmod ham commodo nulla, hamburger tongue sed incididunt duis ham hock sausage ullamco pork belly proident. Tempor strip steak ball tip spare ribs picanha in chicken ground round culpa rump tail pancetta pig. Laboris pariatur pig, exercitation salami do labore andouille aliqua bacon anim dolore. Mollit brisket kevin aliqua enim ut tri-tip.</p>
</body>
</html>