I am trying to save a simple registration form to server using fetch
but getting response false
.
apiDataSave = () => {
fetch('<myapi>', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
name : "abc",
no : "1234567890",
password : "123",
email : "abc@gmail.com"
})
})
.then(function(response) {
return response.json();
})
.then(function(data) {
alert(`response json is: ${JSON.stringify(data)}`)
})
}
I am getting alert as follows:
response json is: {"status":false,"data":[]}
The expected result alert is:
response json is: {"status":true,"data":"1"} // number of records entered in database