-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictform.html
44 lines (40 loc) · 1.11 KB
/
dictform.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
<form onsubmit="submitIt(); return false;">
<label> Word: <input type="text" id="word"></label>
<label><input type="checkbox" id="english"> Word is in English</label>
<label><input type="checkbox" id="json"> Result as JSON</label>
<input type="submit" onclick="submitIt();" value="Look up">
</form>
<div id="result"></div>
<script>
function submitIt() {
var word = document.getElementById('word').value;
var inEnglish = document.getElementById('english').checked;
var asJson = document.getElementById('json').checked;
var result = document.getElementById('result');
var target = 'ROOT/dict/';
if (inEnglish) target += 'eng/';
target += encodeURIComponent(word);
if (asJson)
{
target += '/json';
document.location = target;
}
else
{
target += '?bare';
var xhr = new XMLHttpRequest();
xhr.open('GET', target);
xhr.onload = function() {
if (xhr.status === 200) {
result.innerHTML = xhr.responseText;
}
else {
result.innerHTML = 'Request failed. Returned status of ' + xhr.status;
}
};
xhr.send();
}
event.cancelBubble = true;
return false;
}
</script>