SHARE
TWEET

Untitled

a guest Feb 12th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Server.js
  2. var server = http.createServer(function(request, response) {
  3. fs.readFile(index, function (err, html) {
  4.         if (err) {
  5.             response.writeHead(404)
  6.             response.write("File not found")
  7.             throw err;
  8.         }
  9.     switch(request.method){
  10.             case "GET":
  11.                 if(request.url ==='/'){
  12.                     response.writeHeader(200, {"Content-Type": "text/html"});
  13.                     response.write(html)
  14.                     response.end()
  15.                 }
  16.                 else if(request.url ==='/client.js'){
  17.                     response.writeHeader(200, {"Content-Type": "text/html"});
  18.                     response.write(clientjs)
  19.                     response.end()
  20.                 }
  21.              break;
  22.           case "POST":
  23.                  if (request.url === '/trigger){
  24.                             response.write(data)
  25.                             setTimeout(()=>{
  26.                               GPIO = 1
  27.                             },data)
  28.                             response.end()
  29.  
  30.                     })
  31.                 }
  32. })
  33.    
  34. #client.js
  35. var myForm = document.getElementById('time')
  36. var xhr = new XMLHttpRequest();
  37. xhr.open('POST', 'trigger', true);
  38. xhr.onerror = function(){
  39.     console.log("request error...")
  40. }
  41. xhr.onload = function (){
  42.     if(this.status == 200){
  43.  
  44.  
  45.     }
  46. }
  47. xhr.send(myForm)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top