iron-ajax not working with local json file?

你。 提交于 2019-12-11 11:57:35

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/35857552/iron-ajax-not-working-with-local-json-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!