I have a Meteor app and needs to read data, from a file "/public/_assets/results/mmresults.json", within the file "/client/controllers.js"


#1

I have a Meteor app and needs to read data, from a file “/public/_assets/results/mmresults.json”, within the file “/client/controllers.js”.

I do not want to read the json file from within the file “/server/app.js” which is server side codes.

The following is my file “/public/_assets/results/mmresults.json”:

{items:[{“Draw_Date”:‘2016-01-01’,“Number_0”:“1”,“Number_1”:“1”,“Number_2”:“2”,“Nmber_3”:“3”,“Number_4”:“4”,“Number_5”:“5”},{“Draw_Date”:‘2016-01-03’,“Number_0”:“2”, “Number_1”:“2”,“Number_2”:“3”,“Nmber_3”:“4”,“Number_4”:“5”,“Number_5”:“6”}]}

The following is my codes in my “/client/controllers.js” file (client side codes):

$.getJSON("_assets/results/mmresults.json", function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
The codes in my controllers.js file doesn’t work. Does $.getJSON work on client side or only works on server side?

Also, my app will be running on iOS 10 iPhone and the mmresults.json file needs to be resided on the iPhone and not on the Meteor server.

Please advice.

Thanks,

Brian


#2

Can you open that file in your browser? That should be the first thing to look at. If not you should see an error in your developer console.

If you need this file in on the client why don’t you just put it in the client folder as a js file? Then you won’t have to bother the loading by yourself at all: http://stackoverflow.com/a/15374725/1177905 see the first suggestion here.