COMET-like, . , , - AJAX :
var lines = 0
function getLog(file, lines) {
$.ajax({
type: 'POST',
url: 'http://thissite.com/getLogFile.php?File=' + file + '&Lines=' + lines,
dataType: 'json',
timeout: 400000,
error:
function() {
return false;
},
success:
function(data) {
if (data.Error) {
alert(data.Message)
} else {
if (data.Lines > lines) {
}
getLogFile(file, data.Lines)
}
}
})
}
script :
- , , (, ), 1
- If the number of lines is greater, return new lines and the number of new lines and exit
- After a number of iterations (I use 100), exit and return the existing row count
The data structure returned by the end of the script is JSON:
{
Error: // 0 or 1,
Lines: // Number of lines
Text: // New lines from log file
}
This works the same as "tail -f" on UNIX, but in the browser!
source
share