AJAX常见方法

接口方法:

function dz_ajax(url, params, type) {//AJAX,路径,参数,类型
    
  return new Promise(function(resolve, reject) {
    $.ajax({
      type: type || "post",
      url: url,
      headers: {
        'content-type': 'application/json'
      },
      dataType: 'json',
      data: params || {},
      success: function(data) {
        if (data.code == 200 || data.rows) {

          resolve(data)
          
        } else {
          alert('提交失败!');
          reject()
        }
      },
      error: function(e) {
        console.log(e)
        alert('网络异常');
        reject()
      }
    });
  }).catch(function(e){})
}

  

  调用:

function dataFn(classific_type,_index){//请求,请求类型&index
    
  dz_ajax(base + 'sxjg/sxjcNewmanagements',		{
    "params[reviewProgress]": 1,
    "params[classification]": classific_type,
    "pageSize":pageSize,
    "currentPage":currentPage
  }, "GET")
  .then(res => {
    console.log(res);
    showList[_index] = res.rows
    paintFn(0)//初始化
     
  }).catch(err =>{
  
    console.log(err,"暂无数据");
  })
    
}

  

posted @ 2021-01-29 16:27  淮生  阅读(87)  评论(0编辑  收藏  举报