Search code examples
jsonangularjsangularjs-service

HTTP Get in AngularJs Could not located the Json file


I have tried several times with the following code to get the json data.

var todoApp = angular.module("todoApp", []);

    todoApp.run(function($http) {

        $http.get('todo.json').success(function (data) {

            model.items = data;
        });
    });

here todo.json file is located on the root of the project....what wrong i am doing?


Solution

  • if you are using visual studio with IIS Express to debug then you will have to add a mime type for the static json file otherwise this debug server wont know how to handle the request for this type of file. you can do by

    1.Adding a new web config file in your project (if it dosent exist)
    2.Adding this inside the file

    <system.webServer>
        <staticContent>
          <mimeMap fileExtension=".json" mimeType="text/json" />
        </staticContent>
      </system.webServer>
    

    under config section / tag. More info about this here