我写的函数工作正常,值正确写入我的终端onSubmit,但是我很难拼凑为什么这段代码没有更新我的html.
router.post('/index', function(req, res, next) {
// ...Get form values, do calculations to get toCost value.
console.log('$' + toCost);
$(document).ready(function() {
var output = document.getElementById('cost');
output.innerHTML = toCost;
});
res.location('/');
res.redirect('/');
})
我收到以下错误,jquery正在加载正常.
$is not defined
不可否认,这是一个过度设计的节点/快递应用程序.代码片段包含在邮件请求中的路由文件中.
如何将我的价值放到html上?
玉的布局
extends layout
block content
form(...)
div#cost
解决方法:
通常的方法如下:
router.post('/index', function(req, res) { <<< 'next' removed (only needed if using middleware)
// ...Get form values, do calculations to get toCost value.
console.log('$' + toCost);
res.render('indexTemplate', {cost: toCost}); <<< pass toCost through to jade as 'cost'
});
然后在indexTemplate的jade文件中,您可以像这样引用传入的’cost’变量:
indexTemplate.jade:
extends layout
block content
form(...)
div#cost #{cost} <<< adds the cost variable to page
然后,toCost的值将出现在结果页面中.
服务器端不需要jQuery.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。