Returning HTML With fetch()

后端 未结 5 1870
暗喜
暗喜 2020-11-28 03:45

I\'m trying to fetch a file and return it\'s HTML. However it\'s not as simple as I\'d have imagined.

    fetch(\'/path/to/file\')
    .then(function (respon         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 04:06

    You need to use the .text() method, instead of .json(). This converts the byte stream into plain text, which can be parsed by the browser as HTML.

提交回复
热议问题