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! While you're at it, check out some resources Treehouse students have shared here.
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

Joe Consterdine
13,965 PointsCan't test AJAX in XXamp... error messages?
Hey,
just started learning AJAX and wanted to do a few tests on XXamp.
Getting 2 errors:
XMLHttpRequest cannot load file:///Applications/XAMPP/xamppfiles/htdocs/sites/ajax/localhost/sites/ajax/index.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///Applications/XAMPP/xamppfiles/htdocs/sites/ajax/localhost/sites/ajax/index.html'.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ajax</title>
</head>
<body>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
alert("ok");
}
else {
alert("not ok");
}
}
xhr.open("GET", "localhost/sites/ajax/index.html");
xhr.send();
Thanks!
2 Answers

jason chan
31,009 Pointsyes you can use php as your get file
use your browser in url localhost/index.php served
Do not open it as a file. Open it as a webpage served on server. I hope that helps.

Joe Consterdine
13,965 PointsHey man,
is it not possible to use an index.html file?

jason chan
31,009 Pointsyes you can. AJAX is called with javascript.