I try to send an POST request from Angular 4 to my Laravel backend.
My LoginService has this method:
login(email: string, password: string) {
return this.http.post(`http://10.0.1.19/login`, { email, password })
}
I subscribe to this method in my LoginComponent:
.subscribe(
(response: any) => {
console.log(response)
location.reload()
},
(error: any) => {
console.log(error)
})
And this is my Laravel backend method:
...
if($this->auth->attempt(['email' => $email, 'password' => $password], true)) {
return response('Success', 200);
}
return response('Unauthorized', 401);
My Chrome dev tools says that my request was a success with 200 status code. But my Angular code triggers the error
block and gives me this message:
Http failure during parsing for http://10.0.1.19/api/login
If I return an empty array from my backend, it works... So Angular is trying to parse my response as JSON? How can i disable this?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…