我已經實作了一種更改密碼的方法,即更改資料庫中用戶的密碼。如果我執行該方法,密碼已成功更改,但出現以下錯誤(見截圖)。我讀了幾篇關于stackoverflow的文章。他們中的大多數人說我必須將回應型別更改為 text { responseType: 'text' },但這不適用于我的情況。

用戶服務.ts
changePassword(newPW: string, userId: number) {
return this.http.put("http://localhost:8080/user/reset/password?newPw=" newPW "&userId=" userId, { responseType: 'text' });
}
accountComponent.ts:
@Component({
selector: 'app-account',
templateUrl: './account.component.html',
styleUrls: ['./account.component.css']
})
export class AccountComponent implements OnInit {
public user!: User;
public name!: string;
public hide: boolean = true;
public hideNewPw: boolean = true;
public hideConfirmPw: boolean = true;
private _unsubscribe$: Subject<void> = new Subject();
constructor(private userservice: UserService) { }
ngOnInit(): void {
this.user = this.userservice.user;
this.name = this.user.forename.toUpperCase() ' ' this.user.surename.toUpperCase();
}
onSubmit(f: NgForm) {
if (this.user.password === f.value.currentPassword && f.value.newPassword === f.value.confirmNewPassword) {
this.userservice.changePassword(f.value.newPassword, this.user.userId)
.subscribe();
}
}
uj5u.com熱心網友回復:
在該put方法中,選項物件是第三個引數。
httpClient.put(url, body, options)
所以你需要傳遞{ responseType: 'text' }作為第三個引數。
干杯
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/485601.html
上一篇:你怎么匹配\'
