5

I want to add to my application a configuration JSON file.
I've added it to my project and tried to get it using $http.get:

$http.get('http://localhost/myProject/content.json').success(function (data) {
        // Do stuff...
}).error((data, status, headers, config) => {
        // Failure...
});

The problem is that every time I get an error 404.

2
  • That's because the file isn't there, try entering that address http://localhost/myProject/content.json directly in your browser. Nov 2, 2014 at 13:30
  • The file is there, when I've changed it to txt like Erez said in his answer, it worked
    – Yaniv
    Nov 2, 2014 at 13:39

4 Answers 4

7

This is an issue with your web server mime type configuration - it has none for json, probably. Try renaming the file extension to .txt or .html and it should work.

You can also add the mime type extension to the server. For IIS express, it's web.config. For example:

 <staticContent>
    <remove fileExtension=".json" />
    <mimeMap fileExtension=".json" mimeType="application/json" />
  </staticContent>
1
  • Thanks, another option is to go to the IIS manager and configure it to know JSON in the MIME Types.
    – Yaniv
    Nov 3, 2014 at 7:57
0

put content.json file sibling to index.html and use this:

$http.get('content.json').success(function (data) {
        // Do stuff...
}).error((data, status, headers, config) => {
        // Failure...
});
0
<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>
   **<system.webServer>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
  </system.webServer>**
</configuration>


This works fine.. as what Erez A. Korn has said.
0

In angular 4 store .json file into your root folder of project. all Json file store in same folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.