Angularjs $http-post-未处理错误请求错误(未定义)

Angularjs $http-post-未处理错误请求错误(未定义),angularjs,http,post,Angularjs,Http,Post,我试图做一个职位,以创建一个帐户,我期待一个400错误的请求(用户名已经使用或电子邮件已经使用) 我已经用其他工具(firefox的REST)确认,我收到的消息是正确的400错误,但是AngularJS response.status、response.data和response.statusText都给出了一个“未定义”的值 以下是我的请求在AngularJS中的定义: var req = { method: 'POST', url: m

我试图做一个职位,以创建一个帐户,我期待一个400错误的请求(用户名已经使用或电子邮件已经使用)

我已经用其他工具(firefox的REST)确认,我收到的消息是正确的400错误,但是AngularJS response.status、response.data和response.statusText都给出了一个“未定义”的值

以下是我的请求在AngularJS中的定义:

var req = {
              method: 'POST',
              url: myURL,
              headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json'
                      },
              data: $scope.user
            };

$http(req).then(
    function(response){
      console.log("account created perfectly!");
                      },
    function(response){
      console.log("ERROR " + response.status + ": account cannot be created!");
      // the data is Username/Password
      alert(response.data + " invalid!");
      }

    )

我做错了什么?

你能在这里发布你的检查员截图吗? 看起来请求主体的传递存在一些问题。 当客户端发送错误请求时,会出现4xx错误


另外,对于您的用例,返回状态代码2xx,因为这是有效的业务案例,不应该是4xX。

您是否可以将要发送到服务器端的最终url使用inspector,我试图显示响应,结果是错误:error:$http:baddata Bad JSON Data。我只需要在后端修复它,一切都很好!我收到了400个错误的请求。顺便说一下,我不知道他为什么不处理一个简单的字符串。如果有人知道……请您发布一个plunkr或jsfiddle,以便我可以调查这个问题。