var xmlHTTP = new XMLHttpRequest(); xmlHTTP.open('GET','); xmlHTTP.send(); 

I just keep getting XHR failed loading: GET, can anyone help???

Thanks

2

1 Answer

If the server your contacting doesn't have CORS set in the header (e.g. access-control-allow-origin: *), you will not be able to make the request. If you don't have access to the server to set a CORS header, you'll need to contact the server from a server you do control and then pass that to the browser (either with a CORS header or not if it's served from the same domain)

But your code works fine. The problem is with your not returning

var xmlHTTP = new XMLHttpRequest(); xmlHTTP.open('GET','); xmlHTTP.send(); xmlHTTP.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.body.innerHTML = this.responseText; } }; 

For server status errors, add this to onreadystatechange

if( this.status > 299 && this.readyState == 4) { console.log('Server Error: ' + xmlHTTP.statusText); } 

For xmlHTTP code errors...

xmlHTTP.onerror = function() { console.log('xmlHTTP Error', xmlHTTP.responseText) } 
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.