Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to build interactive (Ajax) server in lua #5

Open
m2030 opened this issue Mar 30, 2018 · 0 comments
Open

how to build interactive (Ajax) server in lua #5

m2030 opened this issue Mar 30, 2018 · 0 comments

Comments

@m2030
Copy link

m2030 commented Mar 30, 2018

i am bit new in Esp8266 trying to build interactive code that make the data updated webserver eventually
so i have a html error trying to solve it but it seem something i dont know if anyone have the reason
my code in lua
`

data = 10
print (data)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
local buf=""
local buf2=""
print(payload)
if data <1000 then data=data+1
elseif data>999 then data=0 end
tmr.delay(700000)
print (data)

 buf = buf.."<!DOCTYPE HTML>\n\n"
 buf = buf.."<html lang=\"en\"  type=\"text/html\">\n"
  buf = buf.."<head><meta charset=\"utf-8\" />\n"
   buf = buf.."<title>Hello, World!</title></head>\n"
 
   
   
     buf = buf.."<style>\n"
      buf = buf.."html {\n"
       buf = buf.."color: red;\n"
        buf = buf.."background-color: #B39D99;\n"
         buf = buf.."font-family :verdana,Arial ,Gemeva ,Arial Black;\n"
          buf = buf.."}\n"
          buf = buf.."</style>\n"
          buf = buf.."<body onload='process()'>\n<h1>Hello, World!</h1>\n"
          
 
          buf = buf.."<div id='div1'>"..data.."</div>\n"
               buf = buf.."<script id=\"myxml\" type=\"text/XML\">\n"

-- buf=buf.." "
buf=buf..""
buf=buf..data
buf=buf.."\n\n​"
buf = buf.."</script>\n"
buf = buf.."<script>\n"
buf=buf.."var xmlHttp=createXmlHttpObject();\n "
buf=buf.."function createXmlHttpObject(){;\n"
buf=buf.."if(window.XMLHttpRequest){\n"
buf=buf.."xmlHttp=new XMLHttpRequest();\n"
buf=buf.."}else{\n"
buf=buf.."xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');\n"
buf=buf.."}\n"
buf=buf.."return xmlHttp; "
buf=buf.."\n"
buf=buf.."}\n"
buf=buf.."function response(){\n"
buf=buf.."xmlResponse=xmlHttp.responseXML;\n"
buf=buf.."xmldoc = xmlResponse.getElementByTagName('data').innerHTML;\n"

   --buf=buf.." for (i = 0; i < x.length; i++) {\n"
     --buf=buf.."if (areEqual = xmlDoc.getElementsByTagName(\'data\').toUpperCase() === nametxt.toUpperCase())\n" {
    --     buf=buf.."document.getElementById(\"xml\").value = x[i];\n"
  --  buf=buf.." }"
    buf=buf.."message = xmldoc[0].firstChild.nodeValue;\n"
    buf=buf.."document.getElementById('div1').innerHTML=message;}\n"
    buf=buf.."function process(){\n"
    buf=buf.."xmlHttp.open('PUT','XML',true);\n"
    buf=buf.."xmlHttp.onreadystatechange=response;\n"
    buf=buf.."xmlHttp.send(null);\n"
    buf=buf.."setTimeout('process()',400);\n"
    buf=buf.."}\n"
    
    buf=buf.."</script>\n" 
          buf = buf.."</body>\n"
   
          buf=buf.."</html>\n"
          conn:send(buf);
          
   
          conn:close();
          collectgarbage();

end)

end)
`
and the error
(index):38 PUT http://192.168.1.8/XML net::ERR_CONNECTION_TIMED_OUT
process @ (index):38
(anonymous) @ VM10646:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10645:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10644:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10643:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10642:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10641:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10640:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10639:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10638:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10637:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10636:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10635:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10634:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10633:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10632:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10631:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10630:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10629:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10628:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10627:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10626:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10625:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10624:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10623:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10622:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10621:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10620:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10619:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10618:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10617:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10616:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10615:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10614:1
(index):32 Uncaught TypeError: Cannot read property 'getElementByTagName' of null
at XMLHttpRequest.response ((index):32)
response @ (index):32
XMLHttpRequest.send (async)
process @ (index):38
(anonymous) @ VM10646:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10645:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10644:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10643:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10642:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10641:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10640:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10639:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10638:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10637:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10636:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10635:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10634:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10633:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10632:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10631:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10630:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10629:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10628:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10627:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10626:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10625:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10624:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10623:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10622:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10621:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10620:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10619:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10618:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10617:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10616:1
setTimeout (async)
process @ (index):39
(anonymous) @ VM10615:1
(index):32 Uncaught TypeError: Cannot read property 'getElementByTagName' of null
at XMLHttpRequest.response ((index):32)
at process ((index):36)
at :1:1

@m2030 m2030 changed the title how to build interative (Ajax) server in lua how to build interactive (Ajax) server in lua Mar 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant