Link to home
Start Free TrialLog in
Avatar of Wolfie7873
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.
<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>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you need "send" the request:
...
            http.open("GET",pat,false);
            http.send(null);
            if( http.status==200 )
...
Avatar of Wolfie7873
Wolfie7873

ASKER

I don't get what I expected from this. I get

HTTP Code: 0

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?