AJAX提交带有Token的数据

时间:2022-02-24 04:53:24

 

$(function () {
            $("#test").click(function () {
                $.ajax({
                    //url: "http://110.87.98.218:40001/Doctor/List",
                    url: "http://localhost:32186/Person/Add",
                    data: { Name: "11", Sex: "", Birthday: "1988-07-06 00:00:00", IdType: 1, IdNo: "350426198807066134", Phone: "18060922856", Email: "", Address: "", ZipCode: "361008", CardNo: "D69372261", IsDefault: 1 },
                    //data:{DeptId:"E45B4C81-C467-41D6-BD27-97755592AF02"},
                    type: "POST",
                    dataType: "json",
                    headers: {
                        Token: '2c16a1a3b40fda7fe3f2109efff5b7c8'//这里是Token
                    },
                    async: false,
                    cache: false,
                    success: function (data) {
                        console.log(data);
                    },
                    error: function (e) {
                        console.log(data);
                    }
                });
            });
        })

当然,后台获取校验Token是以   var Token = System.Web.HttpContext.Current.Request.Headers["Token"];   获取的,如果    “  ”     号  里面 的  Token  换掉的话,JS的Token   也换成一样的