Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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/22.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
Mysql POST请求返回422(不可处理实体)_Mysql_Angularjs_Node.js_Loopbackjs_Strongloop - Fatal编程技术网

Mysql POST请求返回422(不可处理实体)

Mysql POST请求返回422(不可处理实体),mysql,angularjs,node.js,loopbackjs,strongloop,Mysql,Angularjs,Node.js,Loopbackjs,Strongloop,我有一个AngularJS应用程序,它使用node.js和Loopbackjs与mysql数据库通信。我能够在页面的partial home.html方面正确显示我的GET请求,但是当我创建一个新用户时,它返回以下错误: POST http://localhost:3000/api/se_users 422 (Unprocessable Entity) 这是我的密码: partial-create.html <div class="row"> <div class="

我有一个AngularJS应用程序,它使用node.js和Loopbackjs与mysql数据库通信。我能够在页面的
partial home.html
方面正确显示我的GET请求,但是当我创建一个新用户时,它返回以下错误:

POST http://localhost:3000/api/se_users 422 (Unprocessable Entity)
这是我的密码:

partial-create.html

<div class="row">
    <div class="col-md-8">
        <h1>Create a User</h1>
    </div>
</div>

<div class="container-fluid">
    <div class="row">
        <div class="col-md-6 col-md-offset-3">
            <form name="create" ng-submit="se_user()">
                <div class="form-group">
                    <label for="user_id">ID</label>
                    <input type="text" class="form-control" ng-model="user.eid" placeholder="Enter EID">
                </div>
                <div class="form-group">
                    <label for="first_nm">First Name</label>
                    <input type="text" class="form-control" ng-model="user.first_nm" placeholder="Enter First Name">
                </div>
                <div class="form-group">
                    <label for="last_nm">Last Name</label>
                    <input type="text" class="form-control" ng-model="user.last_nm" placeholder="Enter Last Name">
                </div>
                <div class="form-group">
                    <label for="email_adr">Email Address</label>
                    <input type="text" class="form-control" ng-model="user.email_adr" placeholder="Enter Item Type">
                </div>
                <div class="form-group">
                    <label for="user_role">Role</label>
                    <input type="text" class="form-control" ng-model="user.role" placeholder="Enter Status Code">
                </div>
                <div class="form-group">
                    <label for="user_active">Active</label>
                    <div class="radio">
                        <label>
                            <input type="radio" name="optionsRadios" id="optionsRadios1" value="Yes" ng-model="user.active" checked>Yes
                        </label>
                    </div>
                    <div class="radio">
                        <label>
                            <input type="radio" name="optionsRadios" id="optionsRadios2" value="No" ng-model="user.active">No
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label for="mgr_full_nm">Manager Name</label>
                    <input type="text" class="form-control" ng-model="user.mgr_full_nm" placeholder="Enter Full Name">
                </div>
                <div class="form-group">
                    <label for="mgr_eid">Manager EID</label>
                    <input type="text" class="form-control focus" ng-model="user.mgr_eid" placeholder="Enter Manager EID">
                </div>
                <div class="form-group">
                    <label for="insrt_dt">Insert Date</label>
                    <input type="date" class="form-control" ng-model="user.insrt_dt" placeholder="Enter Date">
                </div>
                <div class="form-group">
                    <label for="insrt_user_id">Insert User EID</label>
                    <input type="text" class="form-control" ng-model="user.insrt_user_id" placeholder="Enter User EID">
                </div>
                <div class="form-group">
                    <label for="upd_dt">Update Date</label>
                    <input type="date" class="form-control" ng-model="user.upd_dt" placeholder="Enter Update User Date">
                </div>
                <div class="form-group">
                    <label for="upd_user_id">Update User EID</label>
                    <input type="text" class="form-control" ng-model="user.upd_user_id" placeholder="Enter Update User EID">
                </div>


                <button class="btn btn-primary btn-lg" ng-click="addSe_user()">Create User</button>

                <br>
                <br>
                <pre>
        {{user | json}}
        </pre>

            </form>
        </div>
    </div>
</div>

将您的创建线从

Se_user
.create($scope.user, 
  function(newUser) {
    console.log(newUser);
    // only set pristine here, this
    // callback fires on success
    $scope.create.$setPristine();
  },
  function(err) {
    console.log(err); // will log the error to the console
  }

);

警报不应该妨碍查看dev工具的输出,但是这种结构通过在调用中使用错误回调更容易获得错误响应

按照您的方式,表示您已创建新用户的警报将在发送创建新用户的ajax调用后立即触发,但未收到。服务器响应会有一些延迟,因此您编写的任何代码(取决于正在创建(或出错)的新用户)都需要进入到
.create()
方法的回调中

请参见此处的环回$resource文档:

更新:Chrome控制台-当您在Chrome开发工具中检查网络调用时,应该会看到带有422错误的堆栈跟踪,如以下401错误:


请编辑原始问题,并将跟踪的全文作为代码块发布到其中。

尝试更改标题的内容类型:


您发布了一个服务器端错误,并且只显示了客户端代码。谁能给你指出正确的方向?说得好。我的想法是,错误在于我的代码的语法,无论是在我的ng模型标记、ng提交标记还是在我的.addSe_用户结构中。完全可能,但您也没有包括Se_用户结构,因此再次强调,任何答案都只是猜测问题。我可以提供什么来帮助您诊断问题。抱歉,这可能是一个新手的疏忽,我对AngularJS和所有这一切都很陌生。看看运行api的终端(
slc run
output),并将错误追溯到源代码(它应该已经吐出堆栈跟踪)。或者使用chromedev工具来检查服务器响应,并找到API错误和错误所在的行。我猜应该是
$scope。用户
缺少必填字段。嗨,布莱恩,谢谢你的回复!我已经相应地调整了代码,仍然看到与以前相同的错误。下面是console.log在该错误时返回的内容:'Object{data:Object,status:422,config:Object,statusText:'Unprocessable Entity'}config:Objectdata:Objectheaders:(name)status:422statusText:'Unprocessable Entity'proto:Object’抱歉阅读困难参见上面的更新-找到422错误堆栈跟踪的全文,并将其粘贴到原始问题中。其他可能有帮助的事情-检查
$scope.user
的JSON结构,确保它与
common/models/Se_user.JSON
中定义的必填字段结构匹配。如果可以的话,粘贴这两个以供参考。嘿@Brian!非常感谢你!在查看堆栈跟踪时,它向我指出了错误所在,因此我能够修复表单,并且它可以工作!!非常感谢你!!
Se_user
.create($scope.user);
Se_user
.create($scope.user, 
  function(newUser) {
    console.log(newUser);
    // only set pristine here, this
    // callback fires on success
    $scope.create.$setPristine();
  },
  function(err) {
    console.log(err); // will log the error to the console
  }

);
header: { 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8;application/json' }