0

{ "title":"Sec Engg", "tasks":[{ "title":"Task A", "effortEstimated":1.3 }] }

1
  • I need to set the name & value for the input field ,will u plzz show how to do that .? Commented Jul 12, 2021 at 16:03

2 Answers 2

0

You can use the fetch API provided by Javascript.

const data = { "title":"Sec Engg", "tasks":[{ "title":"Task A", "effortEstimated":1.3 }] };

fetch('http://example.com/movies.json', {
      method: 'POST',
      headers: {
       'Content-type': 'application/json'
    },
     body: JSON.stringfy(data),
    .then(response => response.json());
    .then(data => { console.log('Success', data)
    })
     .catch((error) => { console.log('Error', error)}
 });
Sign up to request clarification or add additional context in comments.

1 Comment

let submitProduct = (event) => { event.preventDefault(); let dataURL = url; Axios.post(dataURL ,job).then((response) => { setSubmitted(true); }).catch((err) => { setErrorMessage(err); }); };
0

You can use (Built in) Fetch Api or axios library to integrate POST Api with it's payload.

Using Fetch :

 async function postData(url = '', data = {}) {

  const response = await fetch(url, {
    method: 'POST', 
    headers: {
      'Content-Type': 'application/json'        
    },
    body: JSON.stringify(data) 
  });
  return response.json(); 
}

Using axios:

async function getPostData(params={}){

  const response =  await axios.post('http://something.com/', params);
  return response;

}

2 Comments

I need to set the name & value for the input field ,will u plzz tell how to do that .?
I tried like this --> <input type="number" placeholder=" Effort Estimated " name="tasks" value={job.tasks.effortEstimated} onChange={changeInput} />

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.