1

I use axios to send a post request in vue to express, but it doesnt work the backend doesnt respond by the message so it isnt sent to frontend and "posted" not printed in the console, however when i post request by postman it works and "posted" is printed.

code in vue.js (frontend)

post(){ //from vue to express
  this.information = {email:this.email, username:this.username, password:this.password}
    axios.post("http://localhost:8081/register", this.information)
    .then(response => this.msg= response.data.messeage); 
}

code in express (backend)

app.post('/register',(req,res) => {

console.log("posted")
res.send({
    
    messeage: "heloooooo"
}) 

})

amro3
  • 55
  • 6
  • In what way does this fail? – David Aug 23 '21 at 16:45
  • 1
    What *does* happen when the AJAX request is made? In your browser's debugging tools, does the AJAX request get made at all? What is the server's response? Are there any errors at all on the browser's development console? – David Aug 23 '21 at 16:50
  • @David yes i checked it now i have this error : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8081/register. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing) – amro3 Aug 23 '21 at 16:54
  • 3
    Does this answer your question? [Understanding CORS](https://stackoverflow.com/questions/25845203/understanding-cors) Or [this](https://stackoverflow.com/questions/25310450/cross-origin-resource-sharing-cors-concept) Or [this](https://stackoverflow.com/q/27365303/328193) etc. – David Aug 23 '21 at 16:56

0 Answers0