gpt4 book ai didi

javascript - 发布 500 错误 : axios behaves differently in two very similar but independent functions in asp.net React 应用程序

转载 作者:行者123 更新时间:2023-11-30 09:13:15 25 4
gpt4 key购买 nike

我有以下两个单独的函数来发布更新 评论。它们几乎相同,但 UpdateComment 函数会抛出 Post 500 错误。

export function PostComment(commentData) {
return dispatch => {

dispatch(dataOperationBegin());

axios({
method: 'post',
url: 'api/AssessmentDiscussionPost/Create',
data: {
Content: commentData.Content,
DoesAgree: commentData.DoesAgree,
ParentPostId: commentData.ParentPostId,
SubmissionId: commentData.SubmissionId,
RubricItemId: commentData.RubricItemId
}
})
.then(response => {
dispatch(postCommentSuccess(response.data));
})
.catch(error => { dataOperationFailure(error) });
};
}


export function UpdateComment(commentData) {
return dispatch => {

dispatch(dataOperationBegin());

axios(
{
method: 'post', url: 'api/AssessmentDiscussionPost/Update',
data: {
Id: commentData.Id,
Content: commentData.Content,
PostOwnerId: commentData.PostOwnerId,
ParentPostId: null,
SubmissionId: commentData.SubmissionId
},
})
.then(response => {
dispatch(updateCommentSuccess(response.data));
})
.catch(error => { dataOperationFailure(error) });
};
}

服务器上有api/AssessmentDiscussionPost/Create对应的web api函数,正确调用:

    [Authorize(Roles = "Student, Instructor")]
[HttpPost]
[Route("api/AssessmentDiscussionPost/Create")]
public AssessmentDiscussionPostDTO Create([FromBody] AssessmentDiscussionPost post)
{

这是 api/AssessmentDiscussionPost/Update 的其他 Web API 函数,它从不被调用:

    [Authorize(Roles = "Student, Instructor")]
[HttpPost]
[Route("api/AssessmentDiscussionPost/Update")]
public AssessmentDiscussionPost Update([FromBody] AssessmentDiscussionPost post)
{

我在这上面花了好几个小时,但仍然毫 headless 绪。有人至少可以指导我确定实际问题。

最佳答案

您的问题肯定与 BE 相关,但是为什么在应该使用 PATCH 或 PUT 时使用 POST 更新内容?也许这就是原因。

关于javascript - 发布 500 错误 : axios behaves differently in two very similar but independent functions in asp.net React 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57022689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com