Angular 7 HTTP Post 500内部服务器错误

时间:2019-06-20 14:09:40

标签: angular http

由于某些原因,第一次提交表单数据时,它可以与Status Code: 200 OK一起正常工作。但是第二个提交的http post方法返回**500 Internal Server Error**。当我重新加载页面时,同样的问题继续。

这是我的尝试,请高手指教

TS服务

 sendData(): Observable<Disciplines[]>  {
    return this.http.get<Disciplines[]>(this.configService.apiUrl + "data?gf=off");
  }

TS组件

提交表单

onSubmit() {

this.requestBody = {
        name: { "en": this.form.value.discipline_en, "de": this.form.value.discipline_de },
        description: { "en": this.form.value.description_en, "de": this.form.value.description_de }
      }
    this.dataService.sendData(this.requestBody)
            .subscribe(data => {                  
              this.notificationService.showNotification("success", "", "Created successfully");

            });
}

2 个答案:

答案 0 :(得分:2)

内部服务器错误不言自明。检查服务器中的日志。您可以看到它已经到达200的服务器,而在处理请求时出现了异常500。您的后端服务出了点问题。

答案 1 :(得分:0)

如@Ntwobike所建议,问题出在您的 Server 代码上,因此是内部 Server 错误响应。

有几个原因导致重新提交表单后第一次提交表单,可能是表单在某些控件上使用一个值“初始化”了自己,而您在此之后没有正确地恢复为“默认”值第一次提交(这在下拉菜单中发生在我身上),然后由于您的后端无法获取所需的所有信息,因此会在某些属性上引发错误。

检查服务器日志,或者如果您有权访问服务器代码,请在服务上放置一些断点。