weixin_33747129 2017-05-22 11:44 采纳率: 0%
浏览 51

HTML中的Node.js更改标签

I am currently "developing" a small Log In Page, and i want to set the "H2" to "Password Incorrect" or something similar, when the User input is invalid.

This is my HTML:

<!DOCTYPE html>
<html>
<head>
<script>
<script src="jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="http://localhost/style2.css">
<script src="server.js"></script>
</head>
   <body id="body">
   <div id="div">
    <h1 id="h1">Log In</h1>
   </div>   
  <form action="" method="post" enctype="multipart/form-data">
     <div id="rahmen">
      <label class="label" for="name">Benutzer:</label>
      <br>
      <input class="input" id="name" name="name"/>
      <br>
      <label class="label" for="passwort">Passwort:</label>
      <br>
      <input class="input" id="passwort" name="passwort"/>
      <br>
      <input id="button" type="submit" value="Log In"/>
      <br>
      <h2 id="h2"></h2>
     </div>
    </form>
   </body>
</html>

My Server.js compares the Input of the User with Values in the DynamoDB (AWS)

(I omitted the Initialization and DynamoDB Code Parts)

Server.js :

var server = http.createServer(function (req, res) {
  if (req.method.toLowerCase() == 'get') {
    displayForm(res);
  } else if (req.method.toLowerCase() == 'post') {
    processAllFieldsOfTheForm(req, res);
  } 
});

function displayForm(res) {
  fs.readFile('test.html', function (err, data) {
    res.writeHead(200, {
      'Content-Type': 'text/html',
      'Content-Length': data.length
    });
    res.write(data);
    res.end();
  });
}

      docClient.query(Params, function(err, data) { 

        switch(true) {
          case(data.Count == 0 || fields.passwort != data.Items[0].Passwort):

            // change h2 to "Username or Password Incorrect" here.....

            break;

          case(fields.passwort == data.Items[0].Passwort):          
            fs.createReadStream('index.html').pipe(res);
            break;
        }  

      });

I don't know how to handle that with Ajax/Bodyparser, i tried many examples, and everytime it's just loading and loading.

BTW: If User input is valid, the redirection to the "index.html" works just fine. I just can't get the Error Message to run.

Can anyone help me out? Code examples highly appriciated!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧