jquery ajax封装通用方法

//发送ajax post请求
function ajaxPost(url, param, successfn, errorfn) {
    ajax("post", "json", param, successfn, errorfn)
}

//发送ajax post请求
function ajaxGet(url, param, successfn, errorfn) {
    ajax("get", "json", param, successfn, errorfn)
}

//公共ajax封装
function ajax(type, dataType, param, successfn, errorfn){
   $.ajax({
        type : type,
        dataType : dataType,,
        data : param,
        url : url,
        async : false,
        success : function(d) {
            successfn(d);
        },
        error : function(e) {
            if( errorfn ) errorfn(e);
        }
    });   
}

//调用方法
var url = "${ctx}/chart/find.do";
var param = {projectid: proejctid, auditUser: userid, partnerid: partnerid,type: type};
ajaxPost(url, param, function(data){

});  

猜你喜欢

转载自blog.csdn.net/fzy629442466/article/details/84785890