English 中文(简体)
表达式和表格审定
原标题:Express.js and form validation

我试图创建一个简单的节点, 包含 Express.js 脚本, 共 3 个数字 。

在索引上我发现:

索引.jade

!!! 5
html
  head
    title Test
  body
    form(name= form1 , method= post , action= / )
      label(for= 1 )
      input#1(type= text , name= 1 )
      label(for= 2 )
      input#2(type= text , name= 2 )
      label(for= 3 )
      input#3(type= text , name= 3 )
      input(name= submit , type= button , value= submit )
    #result

以及 i m 现在正在写入服务器侧面 - 应用js 和 req 和 red 对象, 但如何返回结果... 也结果 = 1 id + 2id + 3id

应用( a.js)

var express = require( express );
    app = express.createServer();
app.use(express.bodyParser());
app.post( / , function(req, res){
  var i = req.param( 1 , null);
  var j = req.param( 2 , null);
  var k = req.param( 3 , null);
  var r = i+j+k;
  res.send(r);

});

How I to send results (r) into div id Result on 索引.jade... so how to return result to 索引.jade

这里还有糊食代码: http://pastebin.com/J9MRFCaE .

最佳回答

简单的话,只要叫你"index.jade" 传递数据(而不是 Res.send(r) ) :

res.render( index , { 
  result: r
});

并在您的 jade 文件中显示“ 结果” 变量 :

#result #{result}

有关的附加信息“https://github.com/visionmedia/jade#code” rel=“nofollow” >jade 代码 rel=“nofollow”> 表达

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签