ajax方法封装

 

/**
* 公用方法:使用AJAX获取数据
* @param {[type]} param [参数]
* @param {[type]} url [路径]
* @param {[type]} callBack [成功的回调函数]
*/
function ajax(param, url, callBack) {
  $.ajax({
    type: "GET",
    url: serverUrl + url,
    data: $.param(param, true),
    success: callBack,
    error: function(xhr) {
      console.error("ERROR:" + url + ", xhr.status:" + xhr.status + ", xhr.statusText:" + xhr.statusText);
    }
  });
}
/**
* 公用方法:使用AJAX提交数据
* @param {[type]} param [参数]
* @param {[type]} url [路径]
* @param {[type]} callBack [成功的回调函数]
*/
function ajaxPost(param, url, callBack) {
  $.ajax({
    type: "POST",
    url: serverUrl + url,
    data: $.param(param, true),
    success: callBack,
    error: function(xhr) {
    console.error("ERROR:" + url + ", xhr.status:" + xhr.status + ", xhr.statusText:" + xhr.statusText);
    }
  });
}

posted @ 2017-02-24 10:27  huliang56  阅读(179)  评论(0编辑  收藏  举报