-
-
Save jakearchibald/fffd22495c81e53e1b5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var url = require('url'); | |
var fs = require('fs'); | |
var server = http.createServer(); | |
server.on('request', function(request, response) { | |
var parsedURL = url.parse(request.url); | |
if (parsedURL.pathname === '/test') { | |
response.socket.write("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nDate: Tue, 31 Mar 2015 12:51:50 GMT\r\nTransfer-Encoding: chunked\r\n\r\n"); | |
response.socket.write("b\r\nHello world\r\n0\r\n\r\n"); | |
response.socket.end(); | |
} | |
else { | |
var testHTML = fs.createReadStream(__dirname + '/test.html'); | |
response.writeHead(200, { | |
'Content-Type': 'text/html' | |
}); | |
testHTML.pipe(response); | |
} | |
}); | |
server.listen(8000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<script> | |
var xhr = new XMLHttpRequest(); | |
xhr.open('HEAD', '/test'); | |
xhr.onload = function() { | |
console.log('yay', xhr); | |
console.log(xhr.responseText); | |
} | |
xhr.onerror = function() { | |
console.log('nay', xhr); | |
} | |
xhr.send(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment