Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: Unexpected token e in JSON at position 1 at JSON.parse (<anonymous>)

I want to get string value by calling API into Angular. Here is what I am doing Service file -

 public getRespondDashboardUrl(): Observable<any> {
    return this.http.get(`ref/RespondDashboardUrl`);
  }

component file

respondDashboardLink: string;
this.refService.getRespondDashboardUrl().subscribe(result => {
  this.respondDashboardLink = result;
});

funcation returns URL as string value https://abcd.xyz.com/Respond/App/index.html#ActionCenter/0

error I am getting

SyntaxError: Unexpected token h in JSON at position 0 at JSON.parse () at XMLHttpRequest.onLoad (http://localhost:4000/vendor.js:33488:51) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4000/polyfills.js:8108:31) at Object.onInvokeTask (http://localhost:4000/vendor.js:78969:33) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4000/polyfills.js:8107:60) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:4000/polyfills.js:7880:47) at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:4000/polyfills.js:8183:34) at invokeTask (http://localhost:4000/polyfills.js:9429:14) at XMLHttpRequest.globalZoneAwareCallback (http://localhost:4000/polyfills.js:9466:21)

like image 335
user327126 Avatar asked Dec 03 '22 18:12

user327126


1 Answers

If you response type is string. more type check responseType.

this.http.get(`ref/RespondDashboardUrl`, {responseType: 'text'})
like image 111
Hsuan Lee Avatar answered Dec 09 '22 16:12

Hsuan Lee