I'm calling a controller method and returning success if the operation is complete.But i keep getting the following error
HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:5000/api/File/create", ok: false, …}headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}status: 200statusText: "OK"url: "http://localhost:5000/api/File/create"ok: falsename: "HttpErrorResponse"message: "Http failure during parsing for http://localhost:5000/api/File/create"error: {error: SyntaxError: Unexpected token s in JSON at position 0
at JSON.parse (<anonymous>)
at XMLHtt…, text: "success"}__proto__: HttpResponseBase
[HttpPost("create")]
public ActionResult<File> Create([FromBody]File file)
{
_fileService.Create(file);
return Ok("success");
}
There is an opened issue and you have many solutions: https://github.com/angular/angular/issues/18396
The best way is to change the responseType:
this.http.get(url, {responseType: 'text'})
This is the reference: https://angular.io/guide/http#requesting-non-json-data
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments