Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
liam johnshon
Courses Plus Student 904 PointsXampp
hey i am using xampp first time on my pc and when i try to make a AJAX request i got an error in console . Error : "XMLHttpRequest cannot load file:///C:/xampp/htdocs/example.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource."
3 Answers

Luke Pettway
16,591 PointsHow are you doing your AJAX call in your JavaScript? This is a normal security measure in place to prevent certain types of security issues. Also, how are you accessing your site, is there a site.dev url?

Jeff Lemay
14,267 PointsStart up the Apache server in Xampp and then go to localhost/example.html (or whatever your file is inside your htdocs folder).

Luke Pettway
16,591 PointsIs your ajax call going to that page as well? Can you post a copy of your code?

Jeff Lemay
14,267 PointsJust want to clarify a bit for OP, the whole reason you have Xampp is so you can run a local server. If you are working off C:/xampp/htdocs/, you're not using xampp. You should be using localhost (which is basically C:/xampp/htdocs/ but gives you extra functionality).
file:///C:/xampp/htdocs/example.html
would now be

liam johnshon
Courses Plus Student 904 Points<html>
<head>
<script>
var ajaxRqst = new XMLHttpRequest();
ajaxRqst.onreadystatechange = function(){
if(ajaxRqst.readyState===4){
document.getElementById("go").innerHTML = ajaxRqst.responseText;
}
};
ajaxRqst.open("GET","example.html");
ajaxRqst.send();
</script>
</head>
<body>
<!--ajax request-->
<div id="go">
</div>
</body>
</html>
</head>
<!--requested page-->
<section>
<h1>Hello you make a ajax request </h1>
</section>

liam johnshon
Courses Plus Student 904 Pointsafter adding ajaxRqst.open("GET","http://localhost/example.html"); this error caught by a browser console :- GET https://localhost/example.html net::ERR_CONNECTION_REFUSED