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){

});  

你可能感兴趣的:(UI)