【发布时间】:2015-04-15 21:29:56
【问题描述】:
我需要使用 node.js 为管理面板开发一个 web 应用程序。我刚刚学习了如何使用 node.js 显示静态 html。
var sys = require("sys"),
my_http = require("http");
fs = require('fs');
my_http.createServer(function(request,response){
fs.readFile("index.html",function(err,data){
if(err){
console.log("error occured");
}
response.writeHead(200, {'Content-Type': 'text/html','Content- Length':data.length});
response.write(data);
response.end();
});
}).listen(7777);
sys.puts("Server Running on 7777");
但我无法理解如何将视图从一个 html 页面更改为另一个页面,例如单击登录按钮时。我之前用过 php,我在表单的操作中给出了 php 文件的名称。同样在node.js中应该做什么?
【问题讨论】:
-
问:你是怎么用 PHP 做的?您编写了一些 HTML,在
<form>中有一个<input>按钮,而表单标签有一个链接到另一个 HTML 页面的action=,不是吗?问:您为什么不对 Node.js 服务器做同样的事情?此链接可能会有所帮助:forum.codecall.net/topic/… -
所以我必须在操作中给出 node.js 文件的名称?我不明白。一开始node.js服务器文件从浏览器运行,我显示html主页,然后点击表单中的提交按钮会发生什么?
标签: javascript php jquery html node.js