我尝试将Angular 4的POST请求发送到我的Laravel后端.
我的LoginService有这个方法:
@H_301_3@login(email: string,password: string) { return this.http.post(`http://10.0.1.19/login`,{email,password}) } @H_301_3@.subscribe( (response: any) => { console.log(response) location.reload() },(error: any) => { console.log(error) } )这是我的Laravel后端方法:
@H_301_3@... if($this->auth->attempt(['email' => $email,'password' => $password],true)) { return response('Success',200); } return response('Unauthorized',401);我的chrome dev工具说我的请求是200个状态代码的成功.但我的Angular代码触发了错误块并给出了我的这条消息:
“解析http://10.0.1.19/api/login期间的Http失败”
如果我从我的后端返回一个空数组,它可以工作……所以Angular试图解析我对json的响应?我怎么能这个呢?