I'm encountering an issue with posting data to the server. When I click on the button to submit the form, the data is received in the API service class but it's not getting sent to the server as expected. All other API methods in the service class are functioning properly, but when it comes to posting data, there seems to be a problem - no response is received from the server and upon checking the database, there are no entries:
service.ts: The orgId parameter is a string passed in the URL as a foreign key for adding addresspostmodel, and the data parameter is a JSON object. To accommodate more fields in the actual table which are auto-generated, I am using data:any. Interestingly, when testing with Postman, the same API and URL work perfectly fine with the given JSON object:
service.ts:
public postFormData(orgId: string, data: any): Observable<AdressModel> {
return this.http.post<any>(`${this.ApiUrl}/${orgId}/addresses`, data).pipe(
tap(response => console.log(response)), catchError(this.handleError));
}
onSubmit(){
this.data =
{
"city": "test",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3b7a6b0b783a4a6aeaaaaafeda0acae">[email protected]</a>",
"name": "test2",
"recipient": "test",
"street": "test",
"zipCode": "12345"
}
this.ApiService.postFormData(this.organizationId, this.data);
}
The data received here is actually fetched from a form, but for illustration purposes, I've provided a mock JSON object. Both the API data and the JSON object appear correct to me when viewed in the console:
{
"city":"test", "email":"[email protected]", "name":"test2", "recipient":"test", "street":"test", "zipCode":"12345" }
Can someone assist in identifying the issue with the logic?