0

当使用 iron-ajax Polymer Web 组件加载本地 json 文件时,返回的响应是 index.html 的内容,而不是 json 文件。

<iron-ajax auto url="data.json" on-response="handleResponse" handle-as="json"></iron-ajax>

我正在“网络”下的 Chrome 开发人员工具中检查响应,给出的响应与 index.html 文件相同。我使用 Polymer 2.0 入门套件作为前端,后端使用 Flask。抱歉,如果这是一个简单的错误,但我是 JavaScript 新手。

我的简化文件结构如下所示:

/app
 |-- app.py
 |-- /static
      |-- index.html
      |-- /bower_components
      |-- /src
           |-- data.json *(file to be loaded)*
           |-- my-app.html
           |-- my-view.html *(view to load file)*

编辑:我相信问题可能与我正在使用的样板中的 app.py 文件中的这个包罗万象有关。我意识到我不明白相对 url 在这个应用程序中是如何工作的。

@app.route("/static/<path:path>")
def static_c(path):
    return current_app.send_static_file(path)

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
    return current_app.send_static_file("index.html")
4

0 回答 0