-1

I am trying a cors-platform API call for a post and get method to register the data in vue js

Note: The API call should be a cross-platform

but I am facing this issue

Response to a preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore not allowed access.

I tried this solution "CORS issue: No 'Access-Control-Allow-Origin' header is present on the requested resource" but still am getting this error. I don't know how to solve this

Here is my code:-

methods:{
signup () {
  console.log("hi i got the response");
  this.$http.get("http://otherSite.com",{
    userName:this.register.username,
    Email:this.register.email,
    Password:this.register.password,
 }).then(function(data){
  console.log(data);
  });
 }
}
Nithya S
  • 127
  • 1
  • 1
  • 9
  • personally, I use this set up: `const cors = require('cors'); app.use(cors({ origin: "http://localhost:8080", credentials: true }));` Make sure you install cors first and put that code into your server file, changing the port of course as needed – A. L Apr 23 '18 at 12:36

1 Answers1

0

You need to activate cors. Here is a cors implementation: https://github.com/expressjs/cors

let cors = require('cors')

let app = express()
app.use(cors())

Just use it and it will work.

Victor Oliveira
  • 1,109
  • 1
  • 12
  • 29