-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.html
More file actions
executable file
·49 lines (48 loc) · 1.44 KB
/
post.html
File metadata and controls
executable file
·49 lines (48 loc) · 1.44 KB
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
<!DOCTYPE html>
<html>
<head>
<title>POST Test</title>
<style>
#responseDiv{ border: solid 1px #444; width: 80%; margin: 3em auto; }
</style>
<script src="jquery-2.2.1.js"></script>
<script>
pair = 1;
function addPair() {
pair++;
$('#form1').append("\n<label>Key: <input type=\"text\" id=\"k" + pair + "\"></label> <label>Value: <input type=\"text\" id=\"v" + pair + "\"></label><br>");
}
function buildStr() {
i = 1;
dStr = "";
while (i < pair) {
dStr += $('#k' + i).val() + "=" + $('#v' + i).val() + "&";
i++;
}
dStr += $('#k' + i).val() + "=" + $('#v' + i).val();
console.log("dStr: " + dStr);
$('#responseDiv').html(dStr);
sendData(dStr);
}
function sendData(dStr) {
$.ajax({
url: $('#url').val(),
type: "POST",
data: dStr,
success: function testS(resp){$('#responseDiv').html(resp);},
error: function testE(resp){$('#responseDiv').html('There was an error<br>\n<br>\n' + resp);},
});
}
</script>
</head>
<body>
<form id="form1">
<label>URL: <input type="text" id="url"></label><br><br>
<label>Key: <input type="text" id="k1"></label> <label>Value: <input type="text" id="v1"></label><br>
</form><br>
<button onclick="addPair()">Add K/V Pair</button><br>
<button onclick="buildStr()">POST</button>
<div id="responseDiv">
</div>
</body>
</html>