Angular JSON parse error

I have a service which calls a web service returning text data. Basically service is trying to return a file content which is mostly text.

here is my service call

getFile(title: string, identifier: string) {
    console.log('returning service');
    return this.http
      .get(this.constructFileURL(title, identifier), { headers: this.createHeader() });
  }

Open in new window


Here is how I am subscribing to it

 getFileContent(title: string, display: DisplayContent, identifier: string) {
    console.log('calling service');
    this.fileService.getFile(title, identifier).subscribe(results => {
      console.log('displaying results');
      display.content = JSON.stringify(results);
      console.log(display.content);
      this.data.changeContent(display);
    });
    return this.fileData;
  }

Open in new window


I am getting following error on the console. Note : 'console.log('displaying results')' is not getting printed on the console

HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK",
error
:
SyntaxError: Unexpected token e in JSON at position 1 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:4200/vendor.js:7822:51) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:14960:31) at Object.onInvokeTask (http://localhost:4200/vendor.js:36079:33) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:14959:36) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.js:14727:47) at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:4200/polyfills.js:15035:34) at invokeTask (http://localhost:4200/polyfills.js:16079:14) at XMLHttpRequest.globalZoneAwareCallback (http://localhost:4200/polyfills.js:16105:17)
text
:
"test"
__proto__
:
Object

Open in new window


Not able to figure out what is wrong. I do convert JSON to string just to be safe as show in the code
Dev MeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
What does the content look like that your service is returning.

F12 to go to the console - click the request (the GET request) - what does the response tab have in it.

What are you expecting your service to send back - what does the data look like?
Dev MeAuthor Commented:
I figured out this one...closing the question.
Dev MeAuthor Commented:
The server had to configure the response type

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
angular 5

From novice to tech pro — start learning today.