我正在尝试从用户(.jade 页面)输入一个整数并将该值作为 body 参数传递。当我尝试使用下面的代码时,该值被转换为字符串。你能帮我吗?
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。
您可以作为字符串传递并在服务器端转换为 int,如下所示:
parseInt(arg);
使用 parseInt 将其转换为整数
parseInt(empid).