How to prevent login prompt in chrome for 401 Unauthorization error for Basic Authentication

2.3k Views Asked by At

The server was responding with 401 error code against an ajax call and that’s why my chrome browser was throwing an ugly login prompt box, before even my client side 401 handlers were called.

1

There are 1 best solutions below

2
Manas Sahu On

For this issue, I have tried a lot of fixes but the easiest one is to include "X-Requested-With": "XMLHttpRequest" in the request header. It instantly fixed the issue in chrome. In this case no need to change anything from the server side.

this.headers = new HttpHeaders({
      "X-Requested-With": "XMLHttpRequest",
      authorization: "Basic your_credential"
    });

note: this I have used in Angular