简体   繁体   中英

node.js - sending an integer as the input parameter in POST request

I am trying to input an integer from the user (.jade page) and pass that value as body parameter. When I try to use the below code, the value is getting converted to string. Can you please help me in this.

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)
}

I want the value to be 1111 when I try to pass that into the POST request.

您可以像这样传递字符串并在服务器端将其转换为int:

parseInt(arg);

使用parseInt将其转换为整数,我应该这样做

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM