Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$http.get of json file always returns 404

Tags:

angularjs

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.

like image 830
Yaniv Avatar asked Mar 18 '23 00:03

Yaniv


1 Answers

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>
like image 185
Erez A. Korn Avatar answered Mar 29 '23 11:03

Erez A. Korn