【问题标题】:how to change control from one html page to another in node.js?如何在 node.js 中将控件从一个 html 页面更改为另一个页面?
【发布时间】: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


【解决方案1】:

首先,

对于 node.js,从路由到重定向的所有内容都需要手动编码。为此,您需要在 node.js 中了解更多信息。您可以参考-http://www.nodebeginner.org/网站进行学习。

另外,如果你想使用一些高级库,你可以通过 -expressjs -http://expressjs.com/starter/basic-routing.html 并且可以谷歌搜索节点快递应用程序。

你的问题-

您必须从 req.url 属性中提取信息,然后相应地分支您的代码以进行文件读取。

更多内容可以在

中找到

http://nodejs.org/api/http.html#http_message_url

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-11
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 2018-12-16
    • 1970-01-01
    • 2020-07-21
    相关资源
    最近更新 更多