Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Server.js
- var server = http.createServer(function(request, response) {
- fs.readFile(index, function (err, html) {
- if (err) {
- response.writeHead(404)
- response.write("File not found")
- throw err;
- }
- switch(request.method){
- case "GET":
- if(request.url ==='/'){
- response.writeHeader(200, {"Content-Type": "text/html"});
- response.write(html)
- response.end()
- }
- else if(request.url ==='/client.js'){
- response.writeHeader(200, {"Content-Type": "text/html"});
- response.write(clientjs)
- response.end()
- }
- break;
- case "POST":
- if (request.url === '/trigger){
- response.write(data)
- setTimeout(()=>{
- GPIO = 1
- },data)
- response.end()
- })
- }
- })
- #client.js
- var myForm = document.getElementById('time')
- var xhr = new XMLHttpRequest();
- xhr.open('POST', 'trigger', true);
- xhr.onerror = function(){
- console.log("request error...")
- }
- xhr.onload = function (){
- if(this.status == 200){
- }
- }
- xhr.send(myForm)
Add Comment
Please, Sign In to add comment