Ruby创建登录帐户

创建登录帐户

页面创建链接
In the views:

< p > Please click <a href="/"> getting
    the other file</a>

In the router:

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Lab Class' });
});

登录帐户设置
In the views:

<html>
  <head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css'>
    <script type="application/javascript" src="/javascripts/index.js"></script>
  </head>
    <body onload="checkForErrors(<%= login_is_correct %>)">
    <p>This is the home page for <%= title %>. Please login</p>


    <form action="welcome" method="POST">
      Username:<br/>
      <input type="text" name="username"><br>
      Password:<br/>
      <input type="password" name="password">
      <br/>
      <input type="submit"></form>
    </form>
  </body>
</html>

In the router:

/* POST from form. */
router.post('/welcome', function(req, res, next) {
  var username= req.body.username;
  var password= req.body.password;


  if (username==='hi' && password==='hi'){
    res.render('welcome', { title: username,  login_is_correct:true });
  } else {
    res.render('index', { title: 'COM3504/6504', login_is_correct:false });
  }
});

In the JavaScript:

//checks if variable isLoginCorrect is set. If not set Displays an alert

function  checkForErrors(isLoginCorrect){

    if  (!isLoginCorrect){

    alert('login  or  password  is  incorrect');

}

}

什么是异步编程
•异步编程是一种能够控制程序的策略,当主线正常流动以外的事件的发生’即当事件发生时执行某些代码
•典型的示例是单击按钮
在JavaScript中如何完成?
•将异步操作存储到事件队列中
•在主线程完成处理后,队列被处理
•排队的操作尽快完成
•他们将结果归还给JavaScript环境
•4种方法:
回调(经典; 超时和间隔(延迟和重复执行; 承诺(新); 等待/异步(较新)

JSON数据结构
•JSON建立在两个结构上:
名称/值对的集合。 在各种语言中,这被认为是对象,记录,结构,字典,哈希表,keyedlist或关联数组值列表的有序列表。 在大多数语言中,这是一个数组,向量,列表或序列。
•数据通过逗号分隔
•卷曲" "支架容纳对象
•方括号{ }保持数组
•记住一个数组可以包含其他阵列

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值