Hi Guys, Sorry if this is the wrong category. I'm just wondering if I can get some assistance with trying to add text to my site from a txt file. I've already added in the following code into my header, <script> var content function loadXMLDoc() { var textfile; if (window.XMLHttpRequest) { textfile = new XMLHttpRequest(); } textfile.onreadystatechange = function () { if (textfile.readyState == 4 && textfile.status == 200) { content = textfile.responseText; } } textfile.open("GET", "localhost/files/myfile.txt", true); textfile.send(); } </script> Code (markup): Then in my HTML source I'm inserting the following, <script type="text/javascript"> loadXMLDoc(); </script> Code (markup): and it's not working. I've tried various different variations of trying to call this function and I'm really new to the ajax side of things. Any suggestions?
Probably a stupid question, but are you running a server on localhost to send the txt file over ? Something like xampp, wamp
Well currently it's on a web hosting server But I do also have Xampp installed and have been trying it on XAMPP. I only threw in Localhost there just so I wasn't publicly sharing the URL. But now that I think about it "localhost/ is going to be looking for a subdirectory instead of "http//localhost/", but either way I've tried it with my domain as well. Can't seem to find anything online for accomplishing this, almost thinking maybe ajax was not meant for loading text from a file onto a page, but more for onclick events. I can accomplish this easily using PHP, but I guess for learning purposes and so I didn't have to use PHP.