亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - Using fetch to request json data in react returns an html page
PHPz
PHPz 2017-05-19 10:47:17
0
2
1216

question

In the react code, a map component needs to be rendered, and a json data is requested. It is expected that the json data will be injected into the map component after the request is successful, but what is seen in the console is that the content in index.html is returned. content, and no json data is returned.

I tried requesting other json files or a non-existent json file, and the content in index.html was also returned

Related codes

 componentWillMount() {
   fetch('../data/wuhan.json')
   .then(function(response) {
     return response.json();
   })
   .then(function(json) {
     echarts.registerMap('wuhan', json);//注冊地圖組件
   })
   .then(function() {
     this.updataSeries();//處理series
   })
 };

Console error

My project directory structure

Check the requested json in the console and return the content in index.html in the public path


I would like to ask everyone, what is the reason for this? The json request has been unsuccessful?

PHPz
PHPz

學(xué)習(xí)是最好的投資!

reply all(2)
滿天的星座

fetch說白了就是個(gè)ajax請求,ajax必須在http協(xié)議下運(yùn)行,放進(jìn)public目錄下,直接fetch('/wuhan.json')Try it

滿天的星座

Can’t fetch A file, maybe what you need is a json-server

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template