HTML:
<!DOCTYPE html>
<html>
<head>
<title>reading file</title>
<meta charset="UTF-8">
<script type="text/javascript" src="/SD_WLAN/js/jquery.js"></script>
<script type="text/javascript" src="/SD_WLAN/js/modernizr.custom.14927.js"></script>
<script type="text/javascript">
function getFileFromServer(url, doneCallback) {
var xhr;
xhr = new XMLHttpRequest();
xhr.onreadystatechange = handleStateChange;
xhr.open("GET", url, true);
xhr.send();
function handleStateChange() {
if (xhr.readyState === 4) {
doneCallback(xhr.status == 200 ? xhr.responseText : null);
}
}
}
function WriteToFile(that) {
if (Modernizr.localstorage) {
// window.localStorage is available!
localStorage["last"] = JSON.stringify(that);
//document.getElementById ('main1').innerHTML= localStorage["last"];
} else {
// no native support for HTML5 storage :(
// maybe try dojox.storage or a third-party solution
}
}
</script>
</head>
<body>
<div id="main"></div>
<div id="main1"></div>
<div id="file"></div>
<script type="text/javascript">
getFileFromServer("http://flashair/sd_wlan/log1.csv", function(text) {
if (text === null) {
// An error occurred
document.getElementById ('file').innerHTML="http://flashair/sd_wlan/log1.csv";
}
else {
// `text` is the file text
var lines = text.split('\n');
var size = lines.length;
document.getElementById ('main').innerHTML= lines[size-2];
WriteToFile(lines[size-2]);
document.getElementById ('file').innerHTML="http://flashair/sd_wlan/log1.csv";
}
});
</script>
</body>
</html>