in my app i am trying to load XML
file in order to use his data.
but i am facing an error in Chrome browser console:
{error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at XMLHttp…,
service.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class ReadDataService {
headers = new HttpHeaders({ 'Content-Type': 'text/xml' });
xml: string;
private _url: string = "../../assets/sf9_commandpacket.xml";
constructor(private _http:HttpClient) {}
getData(): Observable<string> {
return this._http.get<string>(this._url, { headers: this.headers });
}
}
}
i see in the error, that he is trying to load json
, why?
I tried to implement this solution:
this._http.get(this._url, { headers: this.headers, responseType: text / xml }).subscribe(response => { return response; })