Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php http未接收到来自Laravel的传递状态代码_Php_Angularjs_Http - Fatal编程技术网

Php http未接收到来自Laravel的传递状态代码

Php http未接收到来自Laravel的传递状态代码,php,angularjs,http,Php,Angularjs,Http,我正在构建一个前端Angular应用程序和一个单独的Laravel 5.1 API。我正在通过发布重复的电子邮件地址来测试注册验证 当它抛出状态代码错误时 返回新的JsonResponse($errors,422) 我的Angular$http方法根本不接收响应,因此对Angular响应调用success或error方法 但是,如果我从JsonResponse中删除状态代码422: return new JsonResponse($errors); 我可以接收到角度的响应 我觉得这很奇怪,因为

我正在构建一个前端Angular应用程序和一个单独的Laravel 5.1 API。我正在通过发布重复的电子邮件地址来测试注册验证

当它抛出状态代码错误时

返回新的JsonResponse($errors,422)

我的Angular
$http
方法根本不接收响应,因此对Angular响应调用
success
error
方法

但是,如果我从
JsonResponse
中删除状态代码
422

return new JsonResponse($errors);
我可以接收到角度的响应

我觉得这很奇怪,因为使用状态代码
422
仍然会从网络选项卡返回响应,但Angular没有收到:

422(不可处理实体)

回复:电子邮件:[“电子邮件已被接收。”]

我想从Laravel传递状态代码,因为我想要一个非200来触发角度
$http.error
响应

代码片段:

角度的:

signup: function(params) {
    return $http({
        method: 'POST',
        url: url + ver + '/auth/register',
        data: params,
        cache: true
    });
}

Auth.signup(scope.user).success(function(res){
     console.log(res);
}).error(function(err) {
    alertify.error('There was an error with your login credentials. Please try again');
});
Laravel

public function postRegister(Request $request)
{
    $validator = $this->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

protected function buildFailedValidationResponse(Request $request, array $errors)
{
    if ($request->ajax() || $request->wantsJson()) {
        return new JsonResponse($errors, 422);
    }

编辑:我还认为这可能是由于
422
代码未触发角度
错误的问题。表示在顶部添加,但这并没有解决问题

$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http legacy promise方法的成功和错误已被删除 不赞成。改用标准then方法。如果 $httpProvider.useLegacyPromiseExtensions设置为false,则这些 方法将抛出$http/legacy错误

尝试使用
,然后改用

Auth.signup(scope.user).then(function(res) {
    console.log(res);
}, function(err) {
    alertify.error('There was an error with your login credentials. Please try again');
});

嗯,奇怪,这似乎奏效了。不确定为什么弃用会导致中断though@Growler您使用的是$http拦截器吗?如有,请参阅