$.extend($, { /* *ajax调用封装,返回json * url 服务路径 * data一般为js对象 * callback 回调函数 */ MyAjax: function(url, data, callback) { $.ajax({ url: url, data: data, dataType:'json', method: "post", beforeSend:function(){ myLoad();//打开加载层 }, complete:function(data){ closeLoad();//关闭加载层 }, success: function(msg) { if (typeof callback != 'undefined') callback.call(this, msg); } }); } });
?
?
使用: $.MyAjax("/test","data=1",callBack); function callBack(json){ alert(json.msg); }
?