I’m trying to make a web app that will read in a server-side CSV file and display it in a neat, browsable format. The catch is that I want to do it in naked JS/CSS3/HTML5. Is there any way to read and write server-side files with naked JS/CSS3/HTML5? I obviously want this to be OS/browser independent.
What I’ve tried
I have tried implementing some code I found online (a few sites reference it). Below is what I tried while testing: (I just want the test to show the contents of the webpage, itself, in the webpage)
<html>
<head>
<script type="text/javascript" src="readIt.JS"></script>
</head>
<body>
<button onclick="return readIt();">Show the code of the page</button>
<div id="readItOutput"></div>
</body>
</html>
function readIt()
{
file = fopen(getScriptPath("scriptTest.htm"), 0);
file_length = flength(file);
content = fread(file, file_length);
document.getElementById("readIt").innerText = content;
}
However, whenever I run it, under Opera and Chrome, it throws the following:
Opera:
Uncaught exception: ReferenceError: Undefined variable: fopen
Error thrown at line 3, column 1 in readIt() in http://s.supuhstar.operaunite.com/s/content/JS/readIt.JS:
file = fopen(getScriptPath("scriptTest.htm"), 0);
called from line 1, column 0 in <anonymous function>(event) in http://s.supuhstar.operaunite.com/s/content/JS/scripttest.htm:
return readIt();
Chrome:
Uncaught ReferenceError: getScriptPath is not defined
readItreadIt.JS:3
(anonymous function)scripttest.htm:6
onclick
If you want to edit some files from server you need to use XHR object to download file to client side and again use XHR object to send modifed data back to server, also you need some sort of API on you server to send/recieve data.