0

When loading a local json file with the iron-ajax Polymer web component the response returned is the contents of index.html, not the json file.

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

I am checking the response in Chrome developer tools under "Network" and the response given is the same as the index.html file. I am using Polymer 2.0 starter kit as a front end with Flask on the back end. Apologies if this is a simple mistake but I am new to JavaScript.

My simplified file structure looks like:

/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)*

EDIT: I believe the problem may be to do with this catch-all in the app.py file from the boiler plate I am using. I realise I do not understand how the relative url's are working in this application.

@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")
bill88
  • 13
  • 4
  • can you post your file structure? Where is `data.json` located? – Ofisora Sep 04 '17 at 22:47
  • "response returned is the contents of index.html, not the json file" Did you check what is the value returned in the method `handleResponse`? – Ofisora Sep 11 '17 at 10:26
  • At the moment `handleResponse` is just printing to the console. I think the problem is that my app routing returns index.html as the default. I don't know why it is not being caught by the `static_c` routing though as it is in the static directory. – bill88 Sep 13 '17 at 16:45

0 Answers0