Hello everyone,
I have a small question. Here's my code:
For some reason I get undefined at the alert. Am I missing something?
Thank you. FOX
I have a small question. Here's my code:
Code:
<html>
<head>
<title>Test</title>
<script>
function show(id){
var file="test.txt";
alert(file_get_contents(file));
}
function file_get_contents(path){
var httpRequest;
if (window.XMLHttpRequest) {
httpRequest = new XMLHttpRequest();
}
else if (window.ActiveXObject) { // IE 8 and older
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
httpRequest.onreadystatechange = function(){
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
return httpRequest.responseText;
}
}
};
httpRequest.open('GET',path);
httpRequest.send();
}
</script>
</head>
<body>
<form enctype="multipart/form-data" >
<input type="file" width="100%" id="file"/><br/>
<button type="button" onclick="show('file')" width="100%" id="submit">Show</button>
</form>
</body>
</html>
Thank you. FOX
Comment