<button type="submit" class="btn btn-success" onclick="on()">Force ON </button>
<script type="text/javascript">
function on(){req.url="/ledOn";}
</script>
这是我的 HTML 按钮,我只需要将其路由到 server.js 文件中的“ledOn”页面即可执行一些操作。这是 server.js 文件代码。
var http = require('http');
var ejs = require('ejs');
var fs = require('fs');
var system = require('child_process').exec;
//var mraa = require('mraa');
var ledstatus = "off";
//var pin_2 = new mraa.Gpio(2);
//pin_2.dir(mraa.DIR_OUT);
http.createServer(function(req,res) {
res.writeHead(200, {'Content-Type': 'text/html'});
fs.readFile('index.html', 'utf-8', function(err, content) {
if (err) {
res.end('error occurred');
return;
}
var temp = 'some temp';
console.log("Request: " + req.url);
if(req.url === "/ledOn") {
//pin.write(0);
ledstatus = "on";
console.log("pin 7 on");
}
if(req.url === "/ledOff") {
//pin.write(1);
ledstatus = "off";
console.log("pin 7 off");
}
var renderedHtml = ejs.render(content, {temp: temp, ledstatus:ledstatus});
res.end(renderedHtml);
});
}).listen(8080);
** 我想向我的 html 页面添加更多带有更多路由的按钮,以使用它来控制我的 galileo 板,因此将不胜感激 **