Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross domain browser version #404

Closed
thuy-le-ep opened this issue Aug 8, 2016 · 7 comments
Closed

Cross domain browser version #404

thuy-le-ep opened this issue Aug 8, 2016 · 7 comments

Comments

@thuy-le-ep
Copy link

thuy-le-ep commented Aug 8, 2016

Nodejs:

var  axios  =  require("axios");  

axios.get("https://www.google.com.vn")  
    .then(function (response)  {  
      console.log(response);  
       })  
    .catch(function (error)  {  
         console.log(error);  
     });

It work perfect !
But when i run it in browser version:

<script src="https://npmcdn.com/axios/dist/axios.min.js"></script> 
<script>
axios.get("https://www.google.com.vn")  
    .then(function (response)  {  
      console.log(response);  
       })  
    .catch(function (error)  {  
         console.log(error);  
     });
</script>

Error:

XMLHttpRequest cannot load https://www.google.com.vn/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
localhost/:9 Error: Network Error(…)

What i missing ? Sorry i new to axios

@nickuraltsev
Copy link
Member

Your code makes a CORS request to a resource on another domain, but the server does not support CORS. You can learn about CORS here:

@thuy-le-ep
Copy link
Author

So , the browser version used to do while not cross domain?

@nickuraltsev
Copy link
Member

axios can be used to make cross-origin requests as along as the server supports that.

@thuy-le-ep
Copy link
Author

Thanks @nickuraltsev !

@batjko
Copy link

batjko commented Nov 2, 2016

@nickuraltsev So what is a server doesn't send a cors header (and it's not your server so you can't change that), how would axios handle this?
We're still getting this issue.

@Uniphix
Copy link

Uniphix commented Nov 12, 2016

Yeah I am getting this issue to and it's driving me nuts, only happening on firefox

@ngtranthanhtoan
Copy link

I'm using jquery and it's working just fine. But it's still got error with axios

@axios axios locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants