【发布时间】:2019-08-01 16:13:04
【问题描述】:
我目前正在开发一个 Angular 7 应用程序。当我尝试调用http post时,当web api返回成功消息时它工作正常,当api返回错误消息时我得到错误。消息返回类似于 {Error=true, Message="invalid data"}
service.ts
addCustomer(customer: Customer) {
const body: Customer = {
// do...
};
return this.http.post(this.apiurl + 'Products/Post', body);
}
组件.ts
OnSubmit(form: NgForm) {
this.apiservice.addCustomer(form.value).subscribe((data: any) => {
if (data.Error === false) {
this.resetForm(form);
this.toastr.success(data.Message);
} else {
this.toastr.error(data.Message);`enter code here`
}
});
}
【问题讨论】:
-
你在提出 cors 请求吗?
标签: angular