2014-08-05 18:54:38 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<input id="msg" type="text">
|
|
|
|
<button id="send">Send</button>
|
|
|
|
<div id="logs">
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
$(document).ready(function(){
|
|
|
|
$("#send").click(function(){
|
|
|
|
var msg = $("#msg").val();
|
|
|
|
console.log(msg);
|
|
|
|
if (msg.length > 0)
|
|
|
|
$.post("/send", msg);
|
|
|
|
$("#msg").val("");
|
|
|
|
});
|
|
|
|
$("#msg").keyup(function(event){
|
|
|
|
if(event.keyCode == 13){
|
|
|
|
$("#send").click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var lastLog = 0;
|
|
|
|
var updateLog;
|
|
|
|
updateLog = function(data)
|
|
|
|
{
|
|
|
|
console.log("recv ");
|
|
|
|
console.log(data);
|
|
|
|
var lastLog = data.last*1;
|
|
|
|
console.log("lastLog: " + lastLog);
|
|
|
|
var s = "";
|
2014-08-06 16:18:33 +00:00
|
|
|
function htmlEncode(s)
|
|
|
|
{
|
|
|
|
return s.replace(/&(?!\w+([;\s]|$))/g, "&")
|
|
|
|
.replace(/</g, "<").replace(/>/g, ">");
|
|
|
|
}
|
2014-08-05 18:54:38 +00:00
|
|
|
for(var x in data.msgs)
|
|
|
|
{
|
2014-08-06 16:18:33 +00:00
|
|
|
|
|
|
|
s = htmlEncode(data.msgs[x]) + "<BR>" + s;
|
2014-08-05 18:54:38 +00:00
|
|
|
}
|
|
|
|
$("#logs").html(s+$("#logs").html());
|
|
|
|
var failFunction;
|
|
|
|
failFunction = function(){
|
|
|
|
$.getJSON("/logs/"+lastLog, updateLog).fail(failFunction);
|
|
|
|
};
|
|
|
|
$.getJSON("/logs/"+lastLog, updateLog).fail(failFunction);
|
|
|
|
}
|
|
|
|
$.getJSON("/logs", updateLog);
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|