您的当前位置:首页>全部文章>文章详情

fetch的用法

发表于:2023-09-07 08:14:18浏览:147次TAG: #JavaScript

1.GET请求

fetch('/index.php/Product/Index/getRoleByPano?id='+id,{
    method:'get',
    headers:{
        'Content-Type':'application/json'
   }
})
.then(res => res.json())
.then( ({data:data}) =>{
    console.log(data);       
})

2.POST请求

fetch('/Admin/Pay/create',{
    method:'POST',
    body:JSON.stringify({gold:this.price}),
    headers:{
        'Content-Type':'application/json'
   }    
})
.then(res => res.json())
.then( (res) =>{
    let url = "http://hh.maoyingkeji.com/index.php/pay/id/"+res.info;
    window.open(url);   
})