zoukankan      html  css  js  c++  java
  • AJAX工具

    代码如下

    var AppAjax ={
        baseUrl:AppConfig.apiUrl
        //【POST请求】
        ,post:function(pUrl,pData,pSuccessFun){
            pUrl = AppAjax.baseUrl + pUrl;
            $.ajax({
                headers: {
                   token: AppConfig.token
                },
                url:pUrl,
                type:'POST',
                data:JSON.stringify(pData),//pData,//JSON.stringify(),
                contentType:"application/json",
                beforeSend:function (request) {
                },
                success:function(respondData){
                    if(AppAjax.responseFormat(pUrl,respondData)){
                        pSuccessFun(respondData);
                    }
                },
                error:function(respondData){
                    AppAjax.responseFormat(pUrl,respondData)
                }
            });
    
        }
        //【GET请求】
        ,get:function(pUrl,pSuccessFun){
            pUrl = AppAjax.baseUrl + pUrl;
            $.ajax({
                headers: {
                    token: AppConfig.token
                },
                url:pUrl,
                type:'GET',
                contentType:"application/json",
                beforeSend:function (request) {
                },
                success:function(respondData){
                    if(AppAjax.responseFormat(pUrl,respondData)){
                        pSuccessFun(respondData);
                    }
                },
                error:function(respondData){
                    AppAjax.responseFormat(pUrl,respondData)
                }
            });
        }
        //【请求统一处理】
        ,responseFormat:function(url,respondData){
            //console.log(respondData)
            if(respondData.status == 404){
                alert("接口404")
            }else if( respondData.success === false){
                alert(respondData.msg)
                if(respondData.code == 401){
                    window.location.href = AppConfig.loginPage;
                    alert("重新登录")
                }else{
                    $("body").html("<div align='center'><h1>"+respondData.msg+"</h1></div>")
                }
    
            }else{
    
            }
    
            return true;
    
        }
    }
  • 相关阅读:
    泛型冒泡排序继承IComparable接口
    C#中枚举与位枚举的区别和使用
    C#中把二维数组转为一维数组
    一维数组的冒泡排序
    C#控制台的两个二维数组相加
    vs2019连接MySql的连接字符串
    Ajax方法请求WebService实现多级联动
    kafka-manager无法启动解决方法
    SQL优化————Insert
    读写锁
  • 原文地址:https://www.cnblogs.com/devan/p/11044777.html
Copyright © 2011-2022 走看看