| Autor | Zpráva | ||
|---|---|---|---|
| Baterie Profil |
#1 · Zasláno: 31. 3. 2013, 12:56:03
Ahoj všichni, potřebuju vaší pomoc. Mám js script, který vypisuje každe 2s všechny řádky logu. Potřebuju přidat funkci, která ukáže pouze posledních 20 řádků, protože log je velký. Poradite jak? V php bych si to udělal sám, ale nemám podporu php na webu, takže potřebuju vaší pomoc.
Javascript soubor jquery.logviewer.js: (function(jQuery){
var logViewer = function (options) {
doLVHead = function(id) {
jQuery.ajax({type: "HEAD",
url: logViewer.options.logUrl,
cache: false,
complete: function(xhr, textStatus) {
if (textStatus == "success") {
var newLenght = parseInt(xhr.getResponseHeader("Content-Length"));
checkLVLength(newLenght);
}
}
});
},
checkLVLength = function (newLenght){
if (logViewer.curLenght != newLenght) {
if (logViewer.curLenght > newLenght) {
logViewer.curLenght = 0;
jQuery("#" + logViewer.options.targetObjectID).append('\nReseting ... \n');
}
var getBytes = logViewer.curLenght;
var readBytes = parseInt(logViewer.options.readBytes);
if (logViewer.curLenght == 0 && newLenght > readBytes) {
getBytes = newLenght - readBytes;
} else if (logViewer.curLenght > 0) {
getBytes--;
}
jQuery.ajax({type: "GET",
url: logViewer.options.logUrl,
cache: false,
success: function(data) {
data = logViewer.options.callback.call(this, data);
jQuery("#" + logViewer.options.targetObjectID).append(cleanLVtags(data));
var objDiv = document.getElementById(logViewer.options.targetObjectID);
objDiv.scrollTop = objDiv.scrollHeight;
},
beforeSend: function(http){
http.setRequestHeader('Range', 'bytes='+getBytes+'-');
}
});
}
logViewer.curLenght = newLenght;
setMyTimeOut();
},
setMyTimeOut = function(){
if (logViewer.timeoutID > 0) {
window.clearTimeout(logViewer.timeoutID);
}
logViewer.timeoutID = window.setTimeout(doLVHead, logViewer.options.refreshtimeout);
},
cleanLVtags = function(html) {
if (typeof(html) == 'string'){
return html.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
} else {
return html;
}
};
return { init: function(options) {
if (!options ) var options = {};
if (options.logUrl == undefined ) {
alert('Log URL missing');
return false;
}
if (options.refreshtimeout == undefined ) options.refreshtimeout = '2000';
if (options.readBytes == undefined ) options.readBytes = 100;
if (options.callback == undefined ) options.callback = function(data){ return data;};
options.targetObjectID = jQuery(this).attr('id');
logViewer.options = options;
logViewer.curLenght = 0;
logViewer.curLenght = 0;
doLVHead();
}
};
}();
jQuery.fn.extend({
logViewer: logViewer.init
});
})(jQuery)
<html>
<head>
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE"/>
<meta http-equiv="EXPIRES" content="01 Jan 1970 00:00:00 GMT"/>
<meta http-equiv="PRAGMA" content="NO-CACHE"/>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="jquery.logviewer.js"></script>
<script type="text/javascript">
jQuery(document).bind("ready", function() {
jQuery('#logcontent').logViewer({logUrl: '../server.log'});
});
</script>
</head>
<body>
<textarea id="logcontent" WRAP="off" style="width: 98%; height: 98%;" autocomplete="off">
</textarea>
</body>
</html>
|
||
| Gavier Profil |
#2 · Zasláno: 31. 3. 2013, 15:32:31
Zkus použít pro čtení ze souboru něco jako:
$.get('file.txt', function(data) {
var lines = data.split("\n");
for(var i=lines.length-20;i<=lines.length;i++){
$('#logcontent').append('lines[i] + '<br>');
}
});zdroj: http://stackoverflow.com/questions/4408707/jquery-read-text-file-from-file-system |
||
| Baterie Profil |
#3 · Zasláno: 31. 3. 2013, 19:16:25
jo ale já se v js skoro vubec nevyznam, prosím nemůžete mi rovnou ukazat modifikaci mého kodu, kterou bych mohl hned použít? byl bych hrozně rád. já bych nad tím jinak laboroval hodiny.
|
||
|
Časová prodleva: 13 let
|
|||
0