Wolfie7873
asked on
How to read local file and echo to innerHTML?
I want a function that reads a local (server side) file and then drops the content into a div on the main html page. Something isn't working, and I'm not sure what. The code is here, the file 'itworks.html' just has the words 'It works!'
Thanks.
Thanks.
<html>
<head>
</head>
</body>
<script language='javascript'>
function readAndEcho(pat)
{
fh = fopen(pat, 0); // Open the file for reading
if(fh!=-1) // If the file has been successfully opened
{
length = flength(fh); // Get the length of the file
str = fread(fh, length); // Read in the entire file
fclose(fh); // Close the file
// Return the contents of the file
return str;
}
}
</script>
<a href="javascript:void(0)" onClick="document.getElementById('content').innerHTML=readAndEcho('itworks.html')">Click</a>
<div id='content'></div>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I don't get what I expected from this. I get
HTTP Code: 0
HTTP Code: 0
ASKER
My error was a server one, not a code one. Thanks!
>>My error was a server one, not a code one
So, why the grade?
So, why the grade?
...
http.open("GET",pat,false)
http.send(null);
if( http.status==200 )
...