Angular “HTTP Failure during parsing for …” error. Any help greatly appreciated

Clash Royale CLAN TAG#URR8PPP
Angular “HTTP Failure during parsing for …” error. Any help greatly appreciated
I've been trying to learn to deploy a MEAN app, I've used the ng build command, and the app seems to be loading fine, except in places where I have to retrieve data from the database(I'm using mlab), it's showing this error instead:
message: "Http failure during parsing for http://localhost:8080/tickets /ticketList"
Here's my code:
ticket-list.component.ts
import Component, OnInit from '@angular/core';
import UserService from '../user.service';
import HttpClient from '@angular/common/http';
@Component(
selector: 'app-ticket-list',
templateUrl: './ticket-list.component.html',
styleUrls: ['./ticket-list.component.css']
)
export class TicketListComponent implements OnInit
li:any;
constructor(private test:UserService)
del(x)
console.log(x);
this.test.deleteTicket(x);
ngOnInit()
this.test.getTicketList().subscribe(data=>
this.li = data;
)
user.service.ts
import Injectable from '@angular/core';
import HttpClient from '@angular/common/http';
import stringify from '@angular/compiler/src/util';
@Injectable(
providedIn: 'root'
)
export class UserService
constructor(private http:HttpClient)
getTicketList()
return this.http.get("tickets/ticketList", responseType: 'text');
the html file
<div class="ticketList">
<table>
<th>Event Name</th>
<th>Title</th>
<tr *ngFor="let d of li; let i = index">
<td>d.eventName</td>
<td>d.title</td>
<td class="view"><a routerLink="/extendedList" routerlinkActive="active">view</a></td>
<td class="delete"><a (click)="del(d.eventName)"> delete</a></td>
</tr>
</table>
</div>
I'd really appreciate any help in this, I'm still a beginner and the solutions in other stack overflow questions didn't work for me. Thank you in advance.
It seems there's problem in your mongodb cloud service.. just call localhost:8080/tickets/ticketList from postman get request, & see if you're getting correct response
– Shantanu
Aug 12 at 9:23
@rainerhahnekamp I get the same error, even after removing the response type.
– geteds
Aug 12 at 9:27
@Shantanu I get an HTML file as a response, which seems to be the root html file
– geteds
Aug 12 at 9:30
@geteds Then it's not the mlab service give the correct url of your REST service (database url hosted on mlab)
– Shantanu
Aug 12 at 9:46
1 Answer
1
try this:
getTicketList()
return this.http.get("tickets/ticketList", this.setHttpHeader());
setHttpHeader()
const headers = new HttpHeaders().set('Accept', 'application/json').set('Content-Type', 'application/json');
let options = headers: headers;
return options;
Needless to say: With HttpClientModule we don't need to parse data after receiving; It will be done automatically.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What happens if you don't set the responseType in your get call and what is the response of your server?
– rainerhahnekamp
Aug 12 at 9:19