home.html
I cannot seem to figure out how to get the data from res.end(), into this.responseText. it probably has something to do with the location of my server or the type being sent, but as much as I tried I cant figure it out. Note I do not want to use any external technologies to do this. Not express, nor socket.io. I want to do this with the base node modules. If this is not possible Ill accept that as an answer and figure out something else.
<!DOCTYPE html>
<html>
<head>
<title>
Little structure
</title>
<link rel="shortcut icon" href="img/favicon.ico">
</head>
<body>
<div id="demo">
<a href = "home.html">HOME</a>
<h1 id = "enter">Click here</h1>
<button type="button" onclick="loadDoc()">Submit</button></br></br>
</div>
<script>
// First you must post and check to see if account exists
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText)
console.log("GETT");
}
};
xhttp.open("GET", "server.js", false);
xhttp.send();
}
</script>
</body>
</html>
server.js
here is where I am detecting the GET request. What I want is just the res.end data to manipulate it. But it just returns the entire html code.
var http = require('http');
var fs = require('fs');
var server = http.createServer(function (req, res) {
var cookie = "cookie";
if(req.method == "GET")
{
fs.readFile('home.html', "utf8", function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end(cookie);
});
}
});
server.listen(3000);
console.log("listening on 3000");