-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
103 lines (100 loc) · 3.65 KB
/
index.html
File metadata and controls
103 lines (100 loc) · 3.65 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
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
<!DOCTYPE html>
<html>
<head>
<title>Server Connection Test</title>
<style type="text/css">
* { font-family: Verdana; font-size: 96%; }
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
.msg{ background:#aaa;padding:.2em; border-bottom:1px #000 solid;}
.old{ background-color:#246499;}
.new{ background-color:#3B9957;}
.err{ background-color:#992E36;}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript" charset="utf-8">
function addmsg(type, msg) {
/* Simple helper to add a div.
type is the name of a CSS class (old/new/error).
msg is the contents of the div */
$("#messages").append(
"<div class='msg " + type + "'>" + msg + "</div>"
);
}
function waitForMsg(){
$.ajax({ url: "/webtest",
async: true,
cache: false,
// timeout after 1 min
// timeout: 60000,
/* It does not work with a very short interval
like (1s) and it breaks the stack.
For tighter control on the update intervals,
a server-side push state solution may be more appropriate
Something like Socket.IO (Node.js) */
// process successfull response
success: function(data){
var result = JSON.parse(data);
if (result.status === "SUCCESS") {
addmsg("new", result.timestamp+": "+result.status);
}
else if (result.status === "ERROR") {
addmsg("err", result.timestamp+": "+result.status);
}
//call again in .5 sec
setTimeout('waitForMsg()', 500);
},
dataType: "json",
// handle error
error: function(XMLHttpRequest, textStatus, errorThrown){
addmsg("old", textStatus + " (" + errorThrown + ")");
//try again in 15 sec if request error
setTimeout('waitForMsg()',"15000");
},
});
};
$(document).ready(function(){
waitForMsg();
/* Validate the form and post it to the server */
$('#ServerForm').validate({
submitHandler: function(form) {
$.post($(form).attr("action"),
$(form).serialize(),
function(data) {
// handle response
console.log(data);
}, "json");
}
});
});
</script>
</head>
<body>
<div id="messages">
<div class="msg old">
Messages
</div>
</div>
<form action="/webtest" id="ServerForm" >
<fieldset>
<p><label for="sserver">Server</label><em>*</em>
<input type="text" name="server" class="required" value="" />
</p>
<p><label for="sport">Port</label><em>*</em>
<input type="text" name="port" class="required" value="" />
</p>
<p><label for="suser">Username</label><em>*</em>
<input type="text" name="suser" class="required" value="" />
</p>
<p><label for="spass">Password</label><em>*</em>
<input type="text" name="spass" class="required" value="" />
</p>
<input class="submit" type="submit" name="submit" value="Submit" />
</fieldset>
</form>
</body>
</html>