13856129385 / Moon

happy fish
0 stars 0 forks source link

ajax #4

Open 13856129385 opened 8 years ago

13856129385 commented 8 years ago

POST模式 $.ajax({ contentType: "application/x-www-form-urlencoded",
url: url + "admin/login", //请求的url地址 dataType: "json", //返回格式为json data:{"username":username,"password":password}, async: true, //请求是否异步,默认为异步,这也是ajax重要特性 type: "POST", success: function(result) { adminId = result.data; setCookie("adminId",adminId,7200000);
company(); document.location.href="index.html";//请求前的处理 }, error:function(){ alert("请重新登录");

     }
    });

GET模式 $.ajax({ url: url + "admin/detail", //请求的url地址 dataType: "json", //返回格式为json headers:{"adminId":adminId}, data:{"userId":adminId}, async: true, //请求是否异步,默认为异步,这也是ajax重要特性 type: "GET", success: function(res) { var n = res.data; companyId=n.companyId; setCookie("companyId",companyId,7200000);
}, });

var data={"userId":userId,"dataList":dataList} $.ajax({ contentType: "application/json", url: url+"admin/setRight", //请求的url地址 dataType: "json", //返回格式为json headers:{"adminId":adminId}, data:JSON.stringify(data), async: true, //请求是否异步,默认为异步,这也是ajax重要特性 type: "POST", beforeSend: function() { //alert("yes"); }, success: function(result) { if(result.code==200){ alert("权限设置成功!"); document.location.href="admin_list.html";
} }, error:function(){ //alert("111"); } });