{ "title":"Sec Engg", "tasks":[{ "title":"Task A", "effortEstimated":1.3 }] }
2 Answers
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)}
});
1 Comment
rohit sharma
let submitProduct = (event) => { event.preventDefault(); let dataURL =
url; Axios.post(dataURL ,job).then((response) => { setSubmitted(true); }).catch((err) => { setErrorMessage(err); }); };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
rohit sharma
I need to set the name & value for the input field ,will u plzz tell how to do that .?
rohit sharma
I tried like this --> <input type="number" placeholder=" Effort Estimated " name="tasks" value={job.tasks.effortEstimated} onChange={changeInput} />