-
Notifications
You must be signed in to change notification settings - Fork 2
/
search_demo.html
58 lines (52 loc) · 1.92 KB
/
search_demo.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
48
49
50
51
52
53
54
55
56
57
58
<html>
<head>
<title>Etsy jQuery Demo</title>
<script type="application/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="application/javascript">
(function($){
$(document).ready(function(){
$('#etsy-search').bind('submit', function() {
api_key = "enter_your_api_key_here";
terms = $('#etsy-terms').val();
etsyURL = "http://openapi.etsy.com/v2/public/listings/active.js?keywords="+
terms+"&limit=12&includes=Images:1&api_key="+api_key;
$('#etsy-images').empty();
$('<p>Searching for '+terms+'</p>').appendTo('#etsy-images');
$.ajax({
url: etsyURL,
dataType: 'jsonp',
success: function(data) {
if (data.ok) {
$('#etsy-images').empty();
if (data.count > 0) {
$.each(data.results, function(i,item) {
$("<img/>").attr("src", item.Images[0].url_75x75).appendTo("#etsy-images").wrap(
"<a href='" + item.url + "'></a>"
);
if (i%4 == 3) {
$('<br/>').appendTo('#etsy-images');
}
});
} else {
$('<p>No results.</p>').appendTo('#etsy-images');
}
} else {
$('#etsy-images').empty();
alert(data.error);
}
}
});
return false;
})
});
})(jQuery);
</script>
</head>
<body>
<form id="etsy-search">
<input id="etsy-terms" size="32">
<button>Search!</button>
</form>
<div id="etsy-images"></div>
</body>
</html>