Don
Don

Reputation: 1

issue on calling axios in reactJs

I am new to reactJs i need to fetch value from DB using an axios call, But it's showing 404 error Here is my code

axios({
   method: 'POST',
   contentType: 'application/json; charset=utf-8',
   url:'http://localhost/projectName/backend/web/category-master/fetch-category',
   responseType: 'json'
    })

Upvotes: 0

Views: 42

Answers (2)

Sumit Kumar
Sumit Kumar

Reputation: 823

Try the following, First check your url route method if it accepting post method.

axios.post(url,data, {
headers: {
    'authorization': your_token_if_any,
    'Accept' : 'application/json',
    'Content-Type': 'application/json'
}
})
.then(response => {
     // return  response;
})
.catch((error) => {
    //return  error;
});

Upvotes: 0

Ramil Aliyev 007
Ramil Aliyev 007

Reputation: 5452

Problem is missing port number after localhost. Please set port number and try again

axios({
     method: 'POST',
     contentType: 'application/json; charset=utf-8',
     url:'http://localhost:[PORT]/wellnesscc/backend/web/category-master/fetch-category',
     responseType: 'json'
 })

For example:

If your backend applciation's port is 5000, correct version as below:

axios({  
         method: 'POST',
         contentType: 'application/json; charset=utf-8',
         url:'http://localhost:5000/wellnesscc/backend/web/category-master/fetch-category',
         responseType: 'json'
     })

Upvotes: 1

Related Questions