$ http.get的JSON文件总是返回404 [英] $http.get of json file always returns 404

查看:1101
本文介绍了$ http.get的JSON文件总是返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要添加到我的应用程序的配置JSON文件。

我已经把它添加到我的项目,并试图把它使用$ http.get:

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...
});

问题是,每次我得到一个错误404。

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

推荐答案

这是与您的Web服务器的MIME类型配置的一个问题 - 它有没有对JSON,大概。
尝试重命名文件的扩展名为.txt或.html,它应该工作。

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.

您还可以添加MIME类型扩展到服务器。对于IIS前preSS,它的web.config。例如:

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>

这篇关于$ http.get的JSON文件总是返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆