如何解决http baddata Angular错误? [英] How to resolve a http baddata Angular error?

查看:229
本文介绍了如何解决http baddata Angular错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用前端的Angular和后端的J2EE中的应用程序,我做了一个表单,我必须发布要保存在数据库中的数据

帖子工作正常的问题但是我无法在添加后得到服务器响应,总是我得到这个错误(奇怪的是错误是灰色而不是红色而且通常是这样)

I am working on an application using Angular in the frontend and J2EE in the backend , I made a form where i have to post data to be saved in the database
The problem that the post work fine but I cant get the server response after the add ,always i get this error(strangely the error comes in gray color not in red and usually)


错误:[$ http:baddata]
http://errors.angularjs.org/1.6。 4 / $ http / baddata?p0 =%7B%22success%22%7D& p1 =%7B%7D
at angular.min.js:6
at nc(angular.min .js:96)
at angular.min.js:97
at q(angular.min.js:7)
at xd(angular.min.js:97)
at f(angular.min.js:99)
at angular.min.js:134
at m。$ digest(angular.min.js:145)
at m。$ apply(angular.min.js:149)
at l (angular.min.js:102)

Error: [$http:baddata] http://errors.angularjs.org/1.6.4/$http/baddata?p0=%7B%22success%22%7D&p1=%7B%7D at angular.min.js:6 at nc (angular.min.js:96) at angular.min.js:97 at q (angular.min.js:7) at xd (angular.min.js:97) at f (angular.min.js:99) at angular.min.js:134 at m.$digest (angular.min.js:145) at m.$apply (angular.min.js:149) at l (angular.min.js:102)

这是角度代码

$scope.wflow = {
    "worcode": "HELLOoo",
    "wordest": "AVDOSS",
    "worstatus": "ACTIF",
    "worheight": 0,
    "lancode": "EN",
    "worlabel": "Salut monde",
    "wordescription": "Salut monde",
    "size": 0
};
$scope.submitForm = function () {
    console.log(JSON.stringify($scope.wflow));

    $http({
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        url: host + 'api/workflow/add',
        data: $scope.wflow
    }).then(function (response) {
        console.log(response);
    }, function (response) {
        console.log(response);
    });

};

这里是Java one

And here's the Java one

@RequestMapping(value = "/add", method = RequestMethod.POST)
 @ResponseBody
 public ResponseEntity<String> addWorkflow(@RequestBody LWflow lworkflow){
  service.addWorkflow(lworkflow);
  return new ResponseEntity<String>("{\"success\"}", HttpStatus.OK);
 }

如果需要,这是html部分

this is the html part if needed


        <table class="table">
        <tbody>
        <tr>
        <td><b>Code</b></td>
        <td><input type="text" name="worcode" class="form-control" ng-model="wflow.worcode"></td>
        </tr>
        <tr>
        <td><b>Destination</b></td>
        <td><input type="text" name="wordest" class="form-control" ng-model="wflow.wordest"><td>
        </tr>
        <tr>
        <td><b>Status</b></td>
        <td><input type="text" name="worstatus" class="form-control" ng-model="wflow.worstatus"></td>
        </tr>
        <tr>
        <td><b>Height</b></td>
        <td><input type="number" name="worheight" class="form-control" ng-model="wflow.worheight"><td>
        </tr>
        <tr>
        <td><b>Langue</b></td>
        <td><input type="text" name="lancode" class="form-control" ng-model="wflow.lancode"></td>
        </tr>
        <tr>
        <td><b>Label</b></td>
        <td><input type="text" name="worlabel" class="form-control" ng-model="wflow.worlabel"></td>
        </tr>
        <tr>
        <td><b>Description</b></td>
        <td><input type="text" name="wordescription" class="form-control" ng-model="wflow.wordescription"></td>
        </tr>
        <tr>
        <td><b>Taille</b></td>
        <td><input type="number" name="size" class="form-control" ng-model="wflow.size"></td>
        </tr>
        </tbody>
        </table>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Save changes</button>
      </div>
      </form>

请注意错误来自errorCallback函数

note that the error comes from the errorCallback function

推荐答案

这是一个服务器端问题,因为响应无法通过角度读取有效

PS:阅读@georgeawg的最后评论

That was a server side problem because the response was not valid to read by angular
PS: read @georgeawg's last comment

这篇关于如何解决http baddata Angular错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆