0

I am trying to used locally stored json files to pull in information, right now I am just hardcoding the json in a variable, but what I would like to do is point to some json files I have locally

something like -

var myData = "scripts/data/myData.json";

Is something like this possible?

Thanks!

3
  • 1
    You have to make an AJAX request to your JSON File. Are you using AngularJS? Commented Feb 10, 2015 at 23:15
  • @nanndoj Angular - would prefer not to use jquery for now. Commented Feb 10, 2015 at 23:17
  • AJAX doesn't mean its jquery, ajax can be referring anything thats asynchronous call. And yes you have to use a $http call to get it because web javascript cant load files. Commented Feb 10, 2015 at 23:24

2 Answers 2

2

You can do that in this way :

 $http.get("scripts/data/myData.json").success(function(response) {    

            $scope.myData= response

     }).error(function(err) {       

        alert(err);

 })

Please see here working demo

http://plnkr.co/edit/dV1lHIZyoKYNDxbPwHNV?p=preview

Sign up to request clarification or add additional context in comments.

1 Comment

OP, keep in mind that if you are developing locally without a web server (IE your URL begins with file:///), AJAX will likely not work for you.
0

I`m pretty sure that you can not make AJAX request to a file:// protocol.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.