1

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.

2 Answers 2

2

You can pass as string and convert to int on server side like this:

parseInt(arg);
Sign up to request clarification or add additional context in comments.

Comments

0

convert it to integer with parseInt

parseInt(empid).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.