在已知的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,然后完成请求

相关文章:

  • 2021-11-29
  • 2022-01-07
  • 2021-08-27
  • 2021-12-15
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-11
  • 2021-09-18
  • 2021-11-14
  • 2021-07-20
  • 2021-12-10
相关资源
相似解决方案