-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebinterface
46 lines (46 loc) · 1.54 KB
/
webinterface
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Text Levels Checker</title>
</head>
<body>
<h1>Text Levels Checker</h1>
<form id="text-form">
<label for="text-input">Enter your text:</label>
<br>
<textarea id="text-input" name="text" rows="10" cols="50"></textarea>
<br>
<button type="submit">Submit</button>
</form>
<br>
<div id="results">
<p>Lexile level: <span id="lexile-level"></span></p>
<p>CEFR level: <span id="cefr-level"></span></p>
</div>
<script>
// add event listener for form submission
document.getElementById("text-form").addEventListener("submit", function(event) {
event.preventDefault(); // prevent default form submission behavior
var text = document.getElementById("text-input").value;
// make AJAX request to server to get text levels
var xhr = new XMLHttpRequest();
xhr.open("POST", "/get_text_levels", true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
document.getElementById("lexile-level").innerHTML = response.lexile_level;
document.getElementById("cefr-level").innerHTML = response.cefr_level;
document.getElementById("results").style.display = "block"; // show results div
} else {
alert("Error getting text levels: " + xhr.status);
}
}
};
xhr.send(JSON.stringify({"text": text})); // send text as JSON payload
});
</script>
</body>
</html>