-
Notifications
You must be signed in to change notification settings - Fork 8
/
rpscope_ajax.html
55 lines (50 loc) · 1.82 KB
/
rpscope_ajax.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
<html><!DOCTYPE html><html lang="en">
<!-- Simple oscilloscope data capture using AJAX
v0.01 JPB 4/11/21
-->
<head><meta charset="utf-8"/></head><body>
<script type="text/javascript" language="javascript"> "use strict";
function doSubmit() {
// Eliminate default action for button click
// (only necessary if button is in a form)
event.preventDefault();
// Create request
var req = new XMLHttpRequest();
// Define action when response received
req.addEventListener( "load", function(event) {
document.getElementById("responseText").innerHTML = event.target.responseText;
} );
// Create FormData from the form
var formdata = new FormData(document.getElementById("captureForm"));
// Insert form data into request - doesn't work!
//req.open("GET", "/capture.csv");
//req.send(formdata);
// Collect form data and add to request
var params = [];
for (var entry of formdata.entries()) {
params.push(entry[0]+ '=' + entry[1]);
}
console.log("Params: " + params.join(" "));
req.open( "GET", "/capture.csv?" + encodeURI(params.join("&")));
req.send();
}
</script>
<form id="captureForm">
<label for="nsamples">Number of samples</label>
<select name="nsamples" id="nsamples">
<option value=100>100</option>
<option value=200>200</option>
<option value=500>500</option>
<option value=1000>1000</option>
</select>
<label for="xrate">Sample rate</label>
<select name="xrate" id="xrate">
<option value=1000>1000</option>
<option value=2000>2000</option>
<option value=5000>5000</option>
<option value=10000>10000</option>
</select>
<button onclick="doSubmit(event)">Submit</button>
</form>
<pre><p id="responseText"></p></pre>
</body></html>