Estoy tratando de descargar un archivo de csv pero me sale este error "SyntaxError: Unexpected token i in JSON at position 0 at JSON.parse () at XMLHttpRequest.onLoad" Les muestro mis funciones: La función getTransactionCsv manda a llamar al api.
dowloandCsv(){
let _ = this;
let conditions = {
"conditions":{
"transaction_id": _.id,
"date_from": _.dateFrom, //Optional field (AAAA-MM-DD)
"date_until": _.dateUntil, //Optional field (AAAA-MM-DD)
"points": _.points,
"amount": _.amount,
"account": _.account,
"office": _.office,
"reference": _.reference,
"page_ini": "", // Optional field *
"page_end": "", // Optional field *
"export_file": true
}
}
_.apiRequestService.getTransactionCsv(conditions).subscribe(data => _.getRequestFile(data)),
error => console.log("Error"),
() => console.info("OK");
}
getRequestFile(data: any){
var blob = new Blob([data], { type: "text/csv" });
var url = window.URL.createObjectURL(blob);
window.open(url);
console.log(data);
}
<a class="btn backGray" (click)="dowloandCsv()">Descargar</a>
//Este es mi service
getTransactionCsv(conditions){
let _ = this;
let header = new HttpHeaders();
let other_header = header.append('Authorization', 'Bearer ' + localStorage.getItem('tkAccess'));
return _.http.post(_.apiURL + 'transaction/search', conditions, {headers: other_header})
}
application/json
pero debería sertext/csv
)