POST http:// URL 422(不可处理的实体)

时间:2016-07-22 15:26:12

标签: angularjs http-post

我正在尝试通过Angular发布帖子请求。我的代码如下所示,

Javascript代码如下:

GET:

$scope.getRecord = function() {
    debugger;
        $http({
          method: 'GET',
          url: 'SomeURL'
        }).then(function(response) {
          debugger;
          $scope.mainEntity = response.data.anEntity;
        }, function(error) {
          $scope.content = "something went wrong"
        });
      };

发表:

$scope.save = function() {

        debugger;
        var body = JSON.stringify({
          "xyzaa": $scope.value.xyzaa || "One fielfd of its",
          "xyzbb": $scope.value.xyzbb || One fielfd of its,
          "xyzcc": $scope.value.xyzcc || "One fielfd of its",
          "xyzaaa": $scope.value.xyzaaa || "One fielfd of its"

        });
        var request = {
          method: 'POST',
          url: 'Some URL',
          headers: {
            'Content-Type': 'application/json',
            'Access-Control-Allow-Origin' : '*'
          },
          data: body
        };
        $http(request).then(function (result) {
          debugger;
          $scope.getRecord();
        }, function (error) {
          debugger;
          console.log(error)
          alert("error")
        })

      };

好吧,我可以看到post请求返回我以JSON格式完成的数据,但是收到错误:

POST http://localhost:xyz/xyz/a(不可处理的实体)

Object {data:Object,status:422,config:Object,statusText:“Unprocessable Entity”}。

我可以看到正在发布的数据是在数据键中获取的,我可以看到我已经通过的数据,但是我收到了这个错误,它在api中没有变化

0 个答案:

没有答案
相关问题