zoukankan      html  css  js  c++  java
  • html 中 jquery的封装

    jsonAjaxGet(url,type,param,successfn,errorfn){
                var _this = this ;
                $.ajax({
                    type: type,
                    url: _this.API_BASE_URL + url,
                    data: param,
                    dataType: 'json',
                    headers:{
                        'authorization':window.localStorage.getItem('authorization'),
                        'userId':+(window.localStorage.getItem('id')),
                    }, //请求头类型
                    success: function(res){
                        successfn(res) ;   // 回调一个函数
                    },
                    error:function(err){
                        errorfn(err);      // 回调一个函数
                        console.log(err,'错误')
                    }
                });
            },
    
    // 不是json 格式
    jsonAjax(url,type,param,successfn,errorfn){
                var _this = this ;
                $.ajax({
                    type: type,
                    url: _this.API_BASE_URL + url,
                    data: JSON.stringify(param),
                    dataType: 'text',
                    headers:{
                        "content-type":"application/json",
                        'authorization':window.localStorage.getItem('authorization'),
                        'userId':+(window.localStorage.getItem('id')),
                    }, //请求头类型
                    success: function(res){
                        let jsonData = JSON.parse(res)
                        successfn(jsonData) ;
                    },
                    error:function(err){
                        errorfn(err);
                        console.log(err,'错误')
                    }
                });
            },

    作者:人参,每篇随笔皆原创(除非注明原作者的随笔),欢迎指正!

  • 相关阅读:
    实习日记11
    实习日记10
    实习日记9
    实习日记7
    我自己的颜色库
    实习日记5
    实习日记4
    算法导论2:几个习题 2016.1.2
    算法导论1:插入排序和归并排序 2016.1.1
    和算法导论没什么关系0.手电筒过桥问题详解
  • 原文地址:https://www.cnblogs.com/panax/p/14437141.html
Copyright © 2011-2022 走看看