Search code examples
angularresthttpclientangular7

Angular http request return null in chrome but works in firefox


I have faced a strange problem. I have been working for two months with this angular 7 project. Everything was working fine. But suddenly all my HTTP returns null. But it works as expected in Firefox. i reinstall chrome and problem disappear but after a day it starts again. we are using laravel as backend API. status code is 200. but returns null. it is happening in each API (GET, POST). I have tried in another PC and same thing. doesn't work in chrome, works in Firefox. Can anyone explain?
service:

getRecentProjects () {
  return this.http.get(`${ApiUrl}/ati-erp-project`);  
}

component:

this.homeService.getRecentProjects().subscribe(
      (success: any) => {
        console.log(success)
      }, (error: HttpErrorResponse) => {
        console.log(error);
      }
    )

Solution

  • Surprisingly. its a CORS issue. I have been tackling CORS issue with plugin for a long time specially when my back end don't have any headers or permission. But suddenly even after activation of CORS plugin HTTP response was null. when we configured back end with authorization header it works again. So, maybe its new policy for chrome its doesn't show you an error of CORS when you use plugin but returns null in response body.