node.js – 在POST请求中发送一个整数作为input参数

我试图从用户(.jade页面)input一个整数,并将该值作为身体parameter passing。 当我尝试使用下面的代码时,该值正在转换为string。 你能帮我吗?

app.js

var empid = req.body.empid; // getting value from the jade page console.log(empid); // output here is 1111 var requestdata = {1:empid}; console.log(requestdata); // output here is '1111' var options = { url: my URL goes here, method: 'POST', headers: { 'Content-Type': 'application/json' }, auth: { user : username, pass : '****' }, body: JSON.stringify(requestdata) } 

当我尝试将其传递到POST请求时,我希望该值为1111。

您可以传递string,并在服务器端转换为int像这样:

 parseInt(arg); 

把它转换为整数与parseInt,你我应该这样做你的情况

 var empid=parseInt(req.body.empid).