0
I am using the React and when I try to save in the database returns me this error:
Cannot read property 'protocol' of undefined
My code is this:
const baseUrl = "http://localhost:8000/api/employee";
import axios from 'axios';
const employee = {};
employee.list = async () => {
const urlList = baseUrl + "/role";
const res = await axios.get(urlList)
.then(response => {
return response.data;
})
.catch(error => {
return error;
})
return res;
}
employee.save = async (data) => {
const urlSave = baseUrl + "/create";
const res = await axios.post(urlSave.data)
.then(response => {
return response.data;
})
.catch(error => {
return error;
})
return res;
}
export default employee;
one last piece of information my vs code accuses that the data
of Employee.save is not being used anywhere I have tried to use this
and change the way in .env
and nothing works someone can help?
is a mix with your
promise
or usesasync
andawait
or the methodthen
, that is, the code is written totally wrong and so of strange errors.– novic
When you send the post, you have to send the data. For example: You are doing so
await axios.post(urlSave.data)
, I think you wanted to do it like this:await axios.post(urlSave, data)
. And another, if you’re going to use theawait
not so you don’t use thethen
norcatch
– adventistaam
truth another problem that went unnoticed @adventistaam, beyond the
promise
, was not passed the value inpost
!– novic
And as far as I know, first sets up the
axios
.const http = axios.create( ({baseURL: urlbase })
. And then you use the verbs:http.get(), http.post(), etc
– adventistaam
No @adventistaam, is not rule to work, is not required!
– novic
Ah, ta! Blz.....
– adventistaam