I have a web page is running on localhost. This web page has some JavaScript that runs when the page is loaded. I want to see if the web page can connect to the external internet.
I thought I would use Axios, to see if I could hit Google. So, I tried the following:
axios.get('https://www.google.com')
.then(function (res) {
alert('Google found!');
})
.catch(function (err) {
console.log(err);
alert('Cannot find Google');
})
;
When this code runs, I see the following error in my console window:
XMLHttpRequest cannot load https://www.google.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
My question is, how can I use Axios to see if I can reach the internet?