一直返回400错误的话
这是因为防伪标签没有传过去造成,在headers中增加防伪标签传送即可
$.ajax({ // 获取id,challenge,success(是否启用failback) url: "/handlers/api?r=" + Math.random(), type: "post", data: { Type: "chat", P1: "sadassadasd", }, headers: { 'RequestVerificationToken': $('input[name="__RequestVerificationToken"]').val() }, dataType: "json", // 使用jsonp格式 success: function (data) { console.log(data); }, error: function (xhr, status, error) { console.log("Error: " + error); } });razor页面输出这个防伪标签控件
@Html.AntiForgeryToken()