Fetch 网络请求

1.大概格式:

1 fetch("url",{}).then(function(response){
2 console.log(repsonse.status);//http code
3 console.log(repsonse.statusText);//text
4 console.log(repsonse.ok);//boolean
5 })

fetch的返回是promise类型:

  • arrayBuffer();
  • blob();
  • json();
  • text();
  • fromData();

如何改变返回的数据类型

1 fecth("").then(function(response){
2 return response.json().then(function(json){
3 //然后进行dom渲染
4 })
5 
6 
7 
8 })

 

posted @ 2020-09-03 16:57  颜若笑叻  阅读(284)  评论(0)    收藏  举报