Issue
Im trying to refresh a .log file every second to show instant/realtime update straight to the webpage. My HTML is as follows
HTML
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>
<div id="console" style="background-color:black;color:green;overflow:auto;width:500px;height:700px;">
</div>
</body>
Javascript
<script type="text/javascript">
$(document).ready(function(){
setInterval(function(){
$("#console").load('/log/latest.log');
}, 1000;
});
File Setup
Solution
Why you don't use node.js and websocket to resolve this requirement?
You just need to setup a simple node.js server and enable websocket service.In your html page should also add a websocket client.
After that, node.js server helps you to check the log file and websocket helps you to update the results in realtime.If you do this,even if a more complicated business comes out,you can also resolve it very quickly.
Enjoy node.js ;-)
Answered By - CashLee李秉骏
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.