ajax之前加入token验证
在已知的ajax里面添加token验证
用juqery封装组建获取cookies中的cookies var csrfToken = $.cookie('acf_yb_t');
$.ajax({ type: "POST", url: "/wbapi/web/delete/manager", data: postData, contentType: "application/x-www-form-urlencoded; charset=utf-8", dataType: "json", beforeSend: function (xhr) { // //发送ajax请求之前向http的head里面加入验证信息 xhr.setRequestHeader("X-CSRF-TOKEN", csrfToken); // 请求发起前在头部附加token }, success: function (data, status) { if (data.status_code == "200") { manager.showPage(manaerUrl); dialog.YBDialog.Dialog.confirm(res.data); } else { dialog.YBDialog.Dialog.confirm(res.data); } } });
这样就可以在ajax中获取cookies中的token,然后完成请求