我试图从Angular 4向我的Laravel后端发送一个POST请求.
我的登录服务有以下方法:
login(email: string, password: string) {
return this.http.post(`http://10.0.1.19/login`, { email, password })
}
我在我的LoginComponent中订阅此方法:
.subscribe(
(response: any) => {
console.log(response)
location.reload()
},
(error: any) => {
console.log(error)
})
这是我的Laravel后端方法:
...
if($this->auth->attempt(['email' => $email, 'password' => $password], true)) {
return response('Success', 200);
}
return response('Unauthorized', 401);
我的Chrome开发工具说我的请求成功了,状态代码为200.但我的Angular 代码触发了error
块,给了我这个信息:
解析过程中Http失败http://10.0.1.19/api/login次
如果我从后端返回一个空数组,它会工作...那么Angular试图将我的响应解析为JSON?我怎样才能禁用它?