0
votes
axios.get("https://url.example.com/b/478L", {
        headers: {
            'Access-Control-Allow-Origin': '*',
            'Content-Type': 'application/json',
        }
    }).then((response) => console.log(response.data))
        .catch((error) => console.log(error))

My URL is different.

Error:

Access to XMLHttpRequest at 'https://url.example.com/b/478L' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

2
What about the back end, You build that?Shihara Dilshan
No its url of jsonkeeperPrem Jogi
Is there any other solution?Prem Jogi
Not worked for me.Prem Jogi

2 Answers

1
votes

I don't know how server is built. But every back-end frameworks have functionality to handle CORS. For example, in ExpressJS, you can use cors middleware to handle CORS policy. So try to solve that problem on Server Side.

0
votes

If you have your own back end you can solve this problem. For an example in Node/Express back end you can use cors library npm link here

Then in your app.js add this line,

//IMPORT THE LIBRARY
const cors = require('cors');


//ALLOW REQUEST FROM ANY DOMAIN
app.use(cors());

Will fix the error.

If are keep getting this error try different end-point. Or may be you find some thing useful here