I want to learn netcode for Javascript games and my googling lead me to AJAX. I tried an example that pulled text from a .txt file and displayed it in an HTML paragraph, but it didn't work at all for me.
After quitting in frustration (I think I might have ADHD), I came back and googled some more, and it turned out my problem was that Chrome doesn't allow local AJAX calls. It was recommended to install XAMPP and try again.
I don't have a lot of experience with Apache or XAMPP, but I have worked on web pages before so I was a little bit at-home with the basic folder system. I created a http/ folder and placed my index.html, main.js code, and simple .txt file in it. When I tried to run the code from the server, it gave me a different error.
Another bout of frustration hit me but I came back. I returned to google and I found references to CORS and Comet, which I don't 100% understand, but I did glean that the file in question (the .txt file) needed a header. But the problem is .txt files don't really have headers as they are just text and not read as code files. Also, just about everything I could find mentioned adding the header to a PHP file, which isn't relevant for me because I'm using Javascript. I tried adding the header to my .js file for just in case but that did nothing.
Does anyone here have any suggestions for how I can get this simple AJAX code to run locally on my computer so I can move on with my learning objective? Thank you for your time!
Top comments (2)
Hey Dana! Sounds like you still have a (lack of) server problem! When you open your test files in the browser right now, how do you do that? You should be going to
http://localhost/folder/index.html
and that should work!Thank you! That solved my problem. I don't even need to run the server!