jumpserver/templates/log_watch.html

104 lines
3.1 KiB
HTML
Raw Normal View History

2015-11-02 03:18:06 +00:00
<html>
<head>
<link href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<link href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script>
var wsUri = "ws://j:8080/send";
var ws;
function connect(){
ws = new WebSocket(wsUri);
ws.onopen = function(evt){ console.log(evt.data) };
ws.onclose = function(evt){ console.log(evt.data) };
ws.onmessage = function(evt){ console.log(evt.data) };
ws.onerror = function(evt){ console.log(evt.data) };
return ws;
}
function send() {
var data = {
input:$("#input_data").val()
};
console.log('hello');
ws.send(JSON.stringify(data));
$("#message").empty();
ws.onopen = function() {
ws.send(JSON.stringify(data));
};
$("#message").append('<div class="panel-body"><p>');
ws.onmessage = function(event) {
$("#message").append(JSON.parse(event.data).input + "<br>");
};
ws.onclose = function(event) {
$("#message").append('</p></div>');
};
}
{# function send() {#}
{# var ws = new WebSocket("ws://j:8080/send");#}
{##}
{# var data = {#}
{# input:$("#input_data").val(),#}
{# };#}
{##}
{# $("#message").empty();#}
{# ws.onopen = function() {#}
{# ws.send(JSON.stringify(data));#}
{# };#}
{##}
{# $("#message").append('<div class="panel-body"><p>');#}
{# ws.onmessage = function(event) {#}
{# $("#message").append(JSON.parse(event.data).input + "<br>");#}
{# };#}
{##}
{# ws.onclose = function(event) {#}
{# $("#message").append('</p></div>');#}
{# };#}
{# }#}
function disconnect(){
ws.close();
}
</script>
</head>
<body>
<div id="test">
<form class="form-horizontal" role="form">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">>>输入</h5>
</div>
<div class="panel-body">
<div class="form-group">
<div class="col-md-8">
<input type="text" class="form-control" id="input_data" value="">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input type="button" class="btn btn-success" id="input_1_btn" onclick="connect();" value="连接" />
<input type="button" class="btn btn-success" id="input_btn" onclick="send();" value="发送" />
<input type="button" class="btn btn-success" id="input_2_btn" onclick="close();" value="关闭" />
</div>
</div>
</div>
</div>
</form>
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">>> 输出</h5>
</div>
<div class="panel-body">
<div id="message"></div>
</div>
</div>
</body>
</html>
</html>