jQuery Ajax封装

来源:互联网 发布:弯矩计算软件 编辑:程序博客网 时间:2024/05/21 23:31
$.jyAjax = function (options){options.async = (options.async==null || typeof(options.async)=="undefined")? "true" : options.async;options.type = (options.type==null  || typeof(options.type)=="undefined")? "POST" : options.type;options.data = (options.data==null || options.data=="" || typeof(options.data)=="undefined")? {"date": new Date().getTime()} : options.data;options.data["token"] = $.cookie("token");$.ajax({url:options.url,data:options.data,async:options.async,type:options.type,dataType:"json",beforeSend: function(){},success:function(data){alert("请求成功");options.success(data);},error:function(data){alert("请求失败");},complete: function(){}})}

$.jyAjax({    url:apiUrl+"cmsLogin/login.do",data:{'yhm':username,'mm':$.md5(userpwd),'yzm':yzm},type:'POST',success:function(result) {if(result.state == 0){//alert(result.state);$.cookie("token", result.data.token);window.location.href = cmsUrl+"main/index.htm";}else{alert(result.msg);}}      });

原创粉丝点击