如何将JS变量从我的客户端传递到Express服务器?我想要获取一个存储了信息的变量,并在node的服务器端代码中使用它。
发布于 2016-12-01 16:19:29
您应该使用AJAX将变量从客户端发送到服务器:
首先,创建一个处理数据的路由:
router.post('/ajaxRoute', (req,res)=>{
console.log(req.body) //your variables are here.
res.status(200).json({msg:'OK'});
});然后在您的客户端上,调用该路由,发送变量。
使用jQuery:
$.ajax({
url : "/ajaxRoute",
type: "POST",
dataType:'json',
data : yourdata,
success: function(data){
console.log(data.msg); // 'OK'
},
});https://stackoverflow.com/questions/40905568
复制相似问题