首页 > Web开发 > 详细

AJAX常见方法

时间:2021-01-29 17:36:21      阅读:38      评论:0      收藏:0      [点我收藏+]

接口方法:

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,"暂无数据");
  })
    
}

  

AJAX常见方法

原文:https://www.cnblogs.com/fzkbk/p/14345654.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!