zoukankan      html  css  js  c++  java
  • fetch 写法

    fetch("../students.json").then(function(response){
            if(response.status!==200){
                console.log("存在一个问题,状态码为:"+response.status);
                return;
            }
            //检查响应文本
            response.json().then(function(data){
                console.log(data);
            });
    }).catch(function(err){
        console.log("Fetch错误:"+err);
    })
    function status(response){
        if(response.status>=200 && response.status<300){
            return Promise.resolve(response);
        }else{
            return Promise.reject(new Error(response.statusText));
        }
    }
    function json(response){
        return response.json();
    }
    fetch("../students.json",{mode:"cors"})//响应类型“cors”,一般为“basic”;
    .then(status)//可以链接方法
    .then(json) 
    .then(function(data){ 
      console.log("请求成功,JSON解析后的响应数据为:",data); })
    .then(function(response){ 
      console.log(response.headers.get('Content-Type')); //application/json 
      console.log(response.headers.get('Date')); //Wed, 08 Mar 2017 06:41:44 GMT  
      console.log(response.status); //200  
      console.log(response.statusText); //ok  
      console.log(response.type); //cors  
      console.log(response.url); //http://.../students.json })
    .catch(function(err){ 
      console.log("Fetch错误:"+err); 
    })
    fetch('./video/avegers01.ts', {
          // set header
        })
        .then(function(response) {
          return response.arrayBuffer();
        })
        .then(function(arrayBuffer) {
          // data events signal a new fMP4 segment is ready:
          transmuxer.push(new Uint8Array(arrayBuffer));
        });
  • 相关阅读:
    NHibernate错误集锦
    potree的第三方库
    potree的API说明文档
    potreeConverter之数据处理
    potreeConverter之环境配置
    SpringBoot读取配置文件信息
    SpringBoot启动tomcat失败
    AbstractRoutingDataSource动态切换数据源
    多数据源配置(Spring+mybatis)
    单一数据源配置(Spring+Mybatis)
  • 原文地址:https://www.cnblogs.com/enych/p/11730637.html
Copyright © 2011-2022 走看看