[英]how to send variable data from javascript to node js?
I want to send the variable from javascript to node js我想将变量从 javascript 发送到节点 js
here I am storing some data in my javascript variable在这里,我将一些数据存储在我的 javascript 变量中
var roomurl = "this is the data";
And here is my nodejs code这是我的nodejs代码
app.post("/newcall", function(req, res) {
var n = (req.body.roomurl);
console.log("val"+ n);
});
I have included all the dependencies like express and body parser我已经包含了所有的依赖,比如 express 和 body parser
but I am not how to send it但我不怎么发
can I get help in my javascript code or我可以在我的 javascript 代码中获得帮助吗?
any Url from where I can get to now about how do任何 Url 从哪里我可以到现在关于如何做
I send data from java script to node js?我将数据从 java 脚本发送到节点 js? thanks
谢谢
Actually, you should run the node/express application to a specific port, ex 3000实际上,您应该将 node/express 应用程序运行到特定端口,例如 3000
app.listen(3000, () => {
console.log('App running at 3000')
})
Then from your client you should post your data via Fetch API or another http client like this然后从您的客户端,您应该通过 Fetch API 或另一个 http 客户端发布您的数据
fetch('http://localhost:3000/newcall', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({roomurl})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.