简体   繁体   中英

get text file from server with meteor

I'm trying to develop a simple app and I'd like to read from a changing text file on the server with the meteor framework.

A little background: I tried using straight javascript to read the text file, but I got an error when doing this. My javascript was the following:

$.get("./temp.txt",function(returnedData)
{
$("#element").text(returnedData);
},"text/plain");

var text = $("#element").text();

In the web development tools in chromium it says the following when the script is run: "XMLHttpRequest cannot load file:///home/grneggandsam/WebDevelopment/Test/temp.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource."

Edit: I should say that in firefox it appears to be working fine... not sure why it doesn't work in chromium and chrome...

Sorry - I'm pretty new to pulling data off of servers. After doing some research on this error I started to think it might be because I am not using a server-side language. So, I decided to look into the Meteor Framework. I also just want to learn the meteor framework because of its usefulness.

My question is: Is there a way to read a text file with the Meteor framework, and how do you do it?

I guess you are trying to achieve this by writing things to a plain .html file and you are not using a webserver?

That's why you are getting this error. As you can see, the error tells you to use one of those protocols for your AJAX-request: http, data, chrome-extension, https, chrome-extension-resource . You are using the protocol file , which is not in the list.

Just to solve this problem, you don't have to learn the whole Meteor framework. I'd recommend that you install a simple HTTP-Server and try to get your script up and running over there.

Refer to this SO-answer. This answer over there describes how to get a simple HTTP-Server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM