我尝试将Angular 4的POST请求发送到我的Laravel后端.
我的LoginService有这个方法:
login(email: string, password: string) {
return this.http.post(`http://10.0.1.19/login`, { email, password })
}
Run Code Online (Sandbox Code Playgroud)
我在LoginComponent中订阅了这个方法:
.subscribe(
(response: any) => {
console.log(response)
location.reload()
},
(error: any) => {
console.log(error)
})
Run Code Online (Sandbox Code Playgroud)
这是我的Laravel后端方法:
...
if($this->auth->attempt(['email' => $email, 'password' => $password], true)) {
return response('Success', 200);
}
return response('Unauthorized', 401);
Run Code Online (Sandbox Code Playgroud)
我的Chrome开发工具说我的请求是成功的200状态代码.但我的Angular代码触发了error阻止并给了我这条消息:
解析http://10.0.1.19/api/login期间的Http失败
如果我从后端返回一个空数组,它可以工作......所以Angular试图将我的响应解析为JSON?我怎么能禁用它?