[Fixed] Post callback not getting called

Issue

I’m doing a save via my service and it is saving fine:

this.generalService.saveAllGameData(this.gameData).subscribe(
            data => {

                console.log(data);
                
                this.deleteUnrequiredFilesOnSave();
                this.notifyService.changeNotify("Saved!");
                this.router.navigate(["/rooms"]);

            },
            error => {

            },
            () => {

                console.log("Posted!");

            }
            );

And here’s the code in the service:

saveAllGameData(newData: any): Observable<any> {
        const body = newData;
        return this.http.post("" + this.apiDomain() + "/api/gameCentre", body)
    }

But all the stuff inside the data callback doesn’t get called. Any ideas why?
Even the console.log("Posted!"); doesn’t action.

Solution

Judging from the comment, most probably the callbacks aren’t being triggered due to lack of correct response type in the request.

Try the following

saveAllGameData(newData: any): Observable<any> {
  const body = newData;
  return this.http.post(
    "" + this.apiDomain() + "/api/gameCentre", 
    body, 
    { responseType: 'text' }
  );
}

The default responseType is 'json'.

Leave a Reply

(*) Required, Your email will not be published