在ASP.NET mvc中如果在表中使用了@Html.AntiForgeryToken(),ajax post不会请求成功
解决方法是在ajax中加入__RequestVerificationToken:

function Like(id) {
// 获取form表单
 var form = $('form');
// 获取token
 var token = $('input[name="__RequestVerificationToken"]', form).val();
 $.ajax({
    url: '/Manage/Like',
    type: 'POST',
    //   在传入的data中加入__RequestVerificationToken: token
    data: { __RequestVerificationToken: token, profileID: id },
    error: function (xhr) { alert('Error: ' + xhr.statusText); },
    success: function (result) {},
    async: true,
    processData: false
 }); 
}

参考:
-- https://stackoverflow.com/questions/14473597/include-antiforgerytoken-in-ajax-post-asp-net-mvc

相关文章:

  • 2021-10-04
  • 2021-11-24
  • 2021-11-27
  • 2021-09-24
  • 2021-06-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-06-01
  • 2021-11-28
相关资源
相似解决方案