尝试了很多示例,花费了大量时间,但它只是没有解决。如果有人能够在这种情况下帮助我,那将是非常棒的。所以,我想要做的是从p#lessonText.lesson(style='margin-left:1%;' name='desc') #{item.description}
获得价值我需要#{item.description}
传递给我的服务器端。从客户端到服务器端节点的传输值js
这是在服务器端的我的客户端代码
form#myForm()
.container
ul
each item, index in items
#allLessons.container
.lessonsWrap
h3.lesson #{index+1} . Lesson |
p#lessonText.lesson(style='margin-left:1%;' name='desc') #{item.description}
button#butPam.btn.btn-primary(type='submit') Begin
.lesDescription
p(style='margin-left:1%;') Lecturer: #{item.author}
p(style='margin-left:1%;') Level: #{item.level}
script.
$('#myForm').on('submit', function(event){
var createVar = $('#lessonText').text();
alert(createVar);
$.ajax({
url: '/qVal',
method: 'post',
contentType: 'application/json',
data: JSON.stringify({desc: createVar.val()}),
async: true,
success: function(response){
console.log(response);
}
})
});
这里现在我只是想看看,如果我可以创建一个变量,它是从客户端通过。
router.post('/qVal', function(req,res){
console.log("server");
var description = req.body.desc;
console.log(typeof(desc));
console.log(desc);
});
也许我错了使用方法,也许我应该使用GET方法呢? 重要的是说,它看起来我的router.post不起作用。当我写console.log(“服务器”),在控制台单词“服务器”没有出现。
所以你的'console.log(“服务器”);'被解雇? – gaganshera
不是,它不 –
检查您的浏览器的ajax调用的网络选项卡是否触发,并检查请求中的URL。我猜可能是/ qVal路径 – gaganshera