1

I am building an application based on reactjs and expressjs. In the process, I am not able to post form data from reactjs to expressjs.

Here I have tried so far:

Express Routes

router.post('/user_post',(req,res, next)=>{
     console.log(req.body);
     var name=req.body.n_name;
 
 res.send(name);
});

React

var fd1=new FormData();
fd1.append('n_entryDate',entryDate);
                  fd1.append('n_name',name);
                  fd1.append('n_username',username);
                  fd1.append('n_password',password);
                  fd1.append('n_nonAdmin',nonAdmin);
                  fd1.append('n_designation',designation);
                  fd1.append('n_address',address);
                  
                  axios({
                        method: 'post',
                        url:'user_post',
                        data: fd1,
                        headers: { 'Content-Type': 'application/json' }
                        
                      })
                  .then(function (response) {
                        alert(response.data);
                      })
                      .catch(function (error) {
                        alert(error);
                      });

Please let me know what is wrong.

1 Answers1

0

In fact, there was an issue with cache. I cleared it, and everything worked. However, I thank you all.