我有一个 AngularJS 应用程序。
我有以下文件夹结构:
ROOT
-app
-data
index.html
在我的服务中,我加载位于数据文件夹中的 bookmarks.xml 文件:
this.$http.get('data/bookmarks.json').then(...)
当我在本地运行网站时:http://localhost:8080一切正常,文件已加载并呈现。
将应用程序部署到 Microsoft Azure azurewebsites.net 后,我在代码加载 bookmarks.json 文件的位置收到此错误消息:
Possibly unhandled rejection: {"data":"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.","status":404,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"data/bookmarks.json","headers":{"Accept":"application/json, text/plain, /"}},"statusText":"Not Found"}
知道为什么会发生这种情况吗?看起来它无法在数据文件夹中找到该文件。文件当然在那里。尝试过“/data/bookmarks.json” - 没有效果。
最佳答案
在您的 web.config 中,检查该部分。此部分确定您的 Web 应用程序允许提供哪些 MIME 类型。如果您希望能够下载 .json 文件,请确保您具备以下条件:
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
如果您还没有 web.config 文件(例如,如果您只是提供静态内容),请将其添加为您的 web.config:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
关于angularjs - webapp部署到azurewebsites.net后,无法从子文件夹加载xml文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46648194/