-
Notifications
You must be signed in to change notification settings - Fork 0
/
socrata.html
117 lines (109 loc) · 4.04 KB
/
socrata.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
Basic sample API Discovery SOCRATA
</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
#results {
width: 100%;
background-color: #f2f2f2;
margin: 5px;
}
</style>
<script>
$.ajaxSetup({
cache: true
});
$(document).ready(function() {
$('#bt_send').on('click', function() {
sendRequest();
});
$('#text_filter_socrata').on('keypress', function(event) {
if (event.which == 13) {
sendRequest();
event.preventDefault();
}
});
function sendRequest() {
var _data = {
q: $('#text_filter_socrata').val(),
limit: $('#num_results_socrata').val()
};
$.ajax({
url: $('input:radio[name=optionsRadios]:checked').val(),
data: _data,
method: 'GET',
dataType: 'json',
success: function(data) {
console.info(data);
if (data) {
$('#results').html('Total results found: ' + data.resultSetSize);
$('#mygrid').html('');
if (data.resultSetSize >= 1) {
$('#mygrid').append('<ul>');
$.each(data.results, function(index, value) {
$('#mygrid').append('<li><b>' + value.resource.name + '</b>(' + value.resource.type + '): <a target="_blank" href="' + value.link + '">' + value.link + '</a>');
$('#mygrid').append('</li>');
});
$('#mygrid').append('</ul>');
}
} else {
$('#results').html("An error occured:");
}
},
error: function(xhr) {
$('#results').html("An error occured: " + xhr.status + " " + xhr.statusText);
}
});
}
});
</script>
</head>
<body>
<div class="container">
<h3>SOCRATA Resource Search example </h3>
<p>Discovery API <br>
<a target="_blank" href="http://docs.socratadiscovery.apiary.io">http://docs.socratadiscovery.apiary.io</a>
</p>
<form>
<div class="form-group">
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="https://api.eu.socrata.com/api/catalog/v1" checked>
EU API Discovery
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="https://api.us.socrata.com/api/catalog/v1">
US API Discovery
</label>
</div>
</div>
<div class="form-group">
<label for="text_filter_socrata"> Filter <u></u></label>
<input type="text" class="form-control" id="text_filter_socrata" value="Contracts" placeholder="text filter">
</div>
</form>
<form class="form-inline">
<div class="form-group">
<label for="num_results_socrata">Num results</label>
<input type="number" size="3" class="form-control" id="num_results_socrata" value="25">
</div>
</form>
<form>
<div class="form-group">
<button id="bt_send" type="button" class="btn btn-default btn-success">Send</button>
</div>
</form>
<hr>
<div id="results"></div>
<div id="mygrid" style="height: 500px"></div>
</div>
</body>
</html>