Я создаю менеджер посещаемости, когда я вызываю checkin api. Я получаю сообщение об ошибке из-за неожиданного токена в позиции 0, который нашел что-то в моем браузере. Показывает BAD-запрос. Я не уверен, что происходит. Пожалуйста, предложите.
компонент. html
<div class="col-xl-2 col-md-2 btn btn-success" (click)="Attendance()">
<h5>{{ attendanceTime | date: "mediumTime"}}</h5>
<h5>{{attendanceValue}}</h5>
<form [formGroup]="attendanceForm" >
<input type="hidden" formControlName="checkIn" [ngModel]="checkIn">
<input type="hidden" formControlName="checkOut" [ngModel]="checkOut">
</form>
</div>
component.ts
Attendance(){
if(this.attendanceValue === 'Check-in'){
this.checkIn = this.attendanceTime;
this.attendanceValue = "Check-out";
console.log("checkin "+ this.checkIn);
var formData: any = new FormData();
formData.append("checkIn", this.attendanceForm.get('checkIn').value);
this.cs.callAPI(formData, "attendance" ).subscribe(response => {
console.log(this.attendanceForm.value)
let body = response.text();
if (body.status === 1) {
console.log("response.message" + body.message);
this.myapp.showSuccessAlert = true;
this.myapp.successMsg = body.message;
this.myapp.isLoadingResults = false;
} else {
console.log("response.message" + response.message);
this.myapp.showErrorAlert = true;
this.myapp.errorMsg = body.message;
this.myapp.isLoadingResults = false;
}
})
} else{
this.checkOut = this.attendanceTime;
console.log("checkout "+ this.checkOut);
this.attendanceValue = "Check-in";
}
}
callAPI метод из общего сервиса
callAPI(data, apiFunction) {
let formdata = data;
console.log("formdata" + formdata)
let url: string = this.baseUrl + apiFunction;
return this.http
.post<any>(url, formdata)
.pipe(catchError(this.errorHandler));
}
ошибка
POST http://localhost:3000/attendance 400 (Bad Request)
core.js:6014 ERROR HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "Bad Request", url: "http://localhost:3000/attendance", ok: false, …}
message: "Unexpected token - in JSON at position 0"