首页 新闻 会员 周边 捐助

AJAX进行POST请求,出现403错误

0
[已解决问题] 解决于 2023-10-17 17:30

$.ajax({
url: "/api/LiveChanges/Insert",
type: "post",
dataType: "json",
data: {
id: comid,
liveName: liveName,
liveId: liveId,
team: team,
course: course,
liveTeacher: liveTeacher,
livePrincipal: livePrincipal,
liveProperty: liveProperty,
liveState: liveState,
liveRemark: liveRemark
},
headers: headers,
success: function (data) {
layer.close(loading);
if (data.code == 1) {
layer.alert(data.message, { closeBtn: 0 }, function (index) {
location.reload();
});
} else {
layer.alert(data.message);
}
}
});

一不小心成了猴的主页 一不小心成了猴 | 菜鸟二级 | 园豆:204
提问于:2023-10-17 15:32
< >
分享
最佳答案
0

403是Forbidden
比如有身份,但是身份没有足够的权限。一般来说,和你这个发起请求的代码没什么关系,要从服务端排查。

奖励园豆:5
复制粘贴机器人 | 小虾三级 |园豆:720 | 2023-10-17 16:42

[HttpPost]
public IActionResult Insert()
{
try
{
var liveName = Request.Form["liveName"].TryParseByInt(0);
var liveId = Request.Form["liveId"].TryParseByInt(0);
var team = Request.Form["team"].ToString();
var course = Request.Form["course"].ToString();
var liveTeacher = Request.Form["liveTeacher"].ToString();
var livePrincipal = Request.Form["livePrincipal"].TryParseByInt(0);
var liveProperty = Request.Form["liveProperty"].TryParseByInt(0);
var liveState = Request.Form["liveState"].TryParseByInt(0);
var id = Request.Form["id"].TryParseByLong(0);
var liveRemark = Request.Form["liveRemark"].ToString();
var model = new Live_change
{
Id = id,
LiveName = liveName,
LiveId = liveName,
Team = team,
Course = course,
LiveTeacher = liveTeacher,
LiveState = liveState,
LivePrincipal = livePrincipal,
LiveProperty = liveProperty,
AuditOpinion = liveRemark,
Type = 0,
LoginUserId = _web_Util.LoginUser.UserID,
};
if (id != 0)
{
var frontLivePrincipal = _daoLive_Change.Get(model.Id).LivePrincipal;
if (frontLivePrincipal != model.LivePrincipal)
{
var text = "申请";
InsertLogTeacher(model, frontLivePrincipal, text);
}
}
var result = id > 0 ? _daoLive_Change.Update(model) : _daoLive_Change.Insert(model);

      //重新提交并通知合规经理
      if (id == 0)
      {
          QWMessage();
      }
      if (result != null)
      {
          InsertLog(result, id);
      }
      return Ok(new { code = result != null ? 1 : 0, message = result != null ? "保存成功" : "保存失败,请稍后重试" });
  }
  catch (Exception e)
  {
      return Ok(new { code = 0, message = e.ToString() });
  }

}这是控制器代码

一不小心成了猴 | 园豆:204 (菜鸟二级) | 2023-10-17 16:45

@断点小白: 你这是业务代码。要看鉴权部分的代码 ,一般写在过滤器或者中间件里,关键字Authorize

复制粘贴机器人 | 园豆:720 (小虾三级) | 2023-10-17 16:51

@复制粘贴机器人: 感谢,解决了

一不小心成了猴 | 园豆:204 (菜鸟二级) | 2023-10-17 17:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册