fetch

拿到数据必须在response.text()之后,如果在{}里可以直接在第一个.then(data)拿到,如果没有在{}说明第一个then返回了值,在第二个then里的data拿
    fetch('/admin/ArrivalMaster/WarehouseSelectList1').then((response)=>{
        console.log(response.status)//200
        console.log(response.statusText)//OK
        console.log(response.redirected)//false
        response.text().then((data)=>{
            console.log(data)//拿到数据
        })
    })
    fetch('/admin/ArrivalMaster/WarehouseSelectList1').then((response)=>response.text()).then((data)=>{
        console.log(JSON.parse(data))//拿到数据
    })

 

post请求必须要有headers,原来jq的ajax请求data对象要改为字符串拼接

    var payload = 'StartDate=' + StartDate + '&EndDate=' + EndDate + '&ClaimID=' + ClaimID + '&CheckState=' + CheckState + '&CreateSubUser=' + CreateSubUser + '&Customer_Name=' + Customer_Name + '&ExamineState=' + ExamineState + '&ExamineDateStart=' + ExamineDateStart + '&ExamineDateEnd=' + ExamineDateEnd + '&PayType=' + PayType + '&DiffType=' + DiffType + '&PageSize=10&PageNo=' + index
    var paramHeaders = new Headers({
        'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'
    })
    fetch('/admin/ClaimForm/ClaimForm_GetList',{
        method: 'POST',
        body: payload,
        headers:paramHeaders
    }).then((response)=>{
        response.text().then((data)=>{
            var msg = JSON.parse(data)//拿到数据
            if (msg.status.code == 1) {
                Ant.showDialog("loding", 0);
            }
            else {
                if (msg.status.code == -100) {
                    window.parent.location.href = "/Home/";
                } else {
                    Ant.alertWindows("提示", msg.status.msg, 2);
                    Ant.showDialog("loding", 0);
                }

            }
        })
    },(err)=>{
        Ant.alertWindows("提示", err, 2);
        Ant.showDialog("loding", 0);
    })

 

posted @ 2022-07-22 10:03  石头记1  阅读(97)  评论(0)    收藏  举报