-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchImage.html
46 lines (40 loc) · 1.52 KB
/
searchImage.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
<html>
<head>
<title>JSON/Atom Custom Search API Example</title>
</head>
<body>
<input type="text" id="searchField" style="height: 25px; width: 200px;" placeholder="Search"/>
<button onclick="searchImage()" style="height: 25px;">Search</button>
<div id="content">
<script>
function searchImage() {
var me = this,
inputEl = document.getElementById('searchField'),
value = inputEl.value,
xhttp = new XMLHttpRequest();
xhttp.open('GET', "http://192.168.2.8:4786/customsearch?q=" + value, true);
// xhttp.open('GET', url, true);
xhttp.onreadystatechange = function() {
debugger;
if (xhttp.readyState == XMLHttpRequest.DONE) {
console.log(xhttp.responseText);
me.hndlr(xhttp.responseText);
}
};
xhttp.send();
}
function hndlr(response) {
var resText = JSON.parse(response);
if (!resText.items) {
document.getElementById("content").innerHTML = 'No result found.';
return;
}
for (var i = 0; i < resText.items.length; i++) {
var item = resText.items[i];
console.log(item);
document.getElementById("content").innerHTML += '<div><img style="padding: 20px;border: 1px solid #e8e8e8;"src="' + item.link + '"></div><br><br>';
}
}
</script>
</body>
</html>