1

I am trying to call one Spring boot REST API from Angular component and trying to display the result string by using alert(). When I am trying to display, it is giving the error

message: "Unexpected token P in JSON at position 0"

The result of this API is successfully giving back the string "Permission Updated Successfully" at Postman.

MY component code is like the following in my .ts file,

this.manageuserService.modifyUserPermissionApiMethod(this.modificationObj)
  .subscribe((data:any)=> {alert(data);}); 

Where have I gone wrong in implementing this?

2
  • 1
    Does the response you get include the quotes? Otherwise, this is not valid JSON. Commented Aug 10, 2020 at 15:46
  • @Henry- No I am only getting as string without quotes. Commented Aug 10, 2020 at 15:47

1 Answer 1

1

Angular HTTP Client by default expects response type to be 'application/json', but in your case the response from the server it is not a valid JSON ( i suppose it is just simple text - 'text/plain').

You should pass an additional parameter responseType: 'text', please check the following link: https://angular.io/guide/http#requesting-non-json-data

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.