user3180105
user3180105

Reputation: 381

iron-ajax not working with local json file?

In my polymer app, pulling in json data via iron-ajax element works fine, but I can't get it to work with my local json file. I've hosted the app on firebase, but still no luck.

This doesn't work:

<iron-ajax
      auto
      url="data/watchlist.json"
      last-response="{{data}}"
      handle-as="json">
</iron-ajax>

But, this does works:

<iron-ajax
      auto
      url="http://jsonplaceholder.typicode.com/albums/"
      last-response="{{data}}"
      handle-as="json">
</iron-ajax>

What am I doing wrong? Can't tell if I'm doing something wrong with polymer or with ajax/json calls.

Upvotes: 0

Views: 1364

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657148

That is probably a browser limitation for security purposes. Check the browser console you probably get an error that tells you why Chrome is blocking the request. Start up a server that serves this file and fetch it from there. You need to enable CORS support on the server if it is a different one than where you load index.html from.

Upvotes: 1

Related Questions