0
錯誤這是我的角度控制器:創建angularJs
app.controller("custctrl",["$scope","Restangular",function($scope,Restangular){
$scope.createcust=function(){
Restangular.all("customer").post($scope.cust);
console.log($scope.cust);
};
}]);
在控制檯中我能找到的對象,但插入失敗,我得到這個錯誤:
angular.js:10765 POST http://localhost:9000/customer 400 (錯誤請求)
我使用一個模式,這是我的代碼的一部分:
<div id="inputModalCust" class="modal fade" ng-controller="custctrl" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><Strong><i class="fa fa-file"></i> Customer </Strong></h4>
</div>
<div class="modal-body">
<form class="form-horizontal" >
<div class="form-group">
<label for="input" class="col-md-2 control-label">Name</label>
<div class="col-md-10">
<input type="text" ng-model="cust.identity.companyName" class="form-control" placeholder="Value">
</div>
</div>
<div class="form-group">
<label for="input" class="col-md-2 control-label">logo</label>
<div class="col-md-10">
<input type="text" ng-model="cust.logo" class="form-control" placeholder="Value">
</div>
</div>
<div class="form-group">
<label for="input" class="col-md-2 control-label">Email</label>
<div class="col-md-10">
<input type="text" ng-model="cust.linkset" class="form-control" placeholder="Value">
</div>
</div>
<div class="form-group">
<label for="input" class="col-md-2 control-label">Phone</label>
<div class="col-md-10">
<input type="text" ng-model="cust.colorSet" class="form-control" placeholder="Value">
</div>
</div>
<div class="form-group">
<label for="input" class="col-md-2 control-label">Website</label>
<div class="col-md-10">
<input type="text" ng-model="cust.webSite" class="form-control" placeholder="Value">
</div>
</div>
<div class="form-group">
<label for="input" class="col-md-2 control-label">Category</label>
<div class="col-md-10">
<input type="text" ng-model="cust.category" class="form-control" placeholder="Value">
</div>
</div>
<div class="form-group">
<label for="input" class="col-md-2 control-label">Time zone</label>
<div class="col-md-10">
<input type="text" ng-model="cust.timeZone" class="form-control" placeholder="Value">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-default" ><i class="gi gi-remove_2"></i> <Strong>Close</Strong></button>
<button type="button" data-dismiss="modal" class="btn btn-primary" ng-click="createcust()"><i class="gi gi-floppy_saved" ></i><Strong> Save</Strong></button>
</div>
</div>
</div>
</div>
的反應是告訴你要發送的數據是不正確的(狀態400) – FRECIA
但我用郵遞員測試了相同的數據,它的工作正常 – Rajeun
你是否正在從同一臺服務器執行'POST'調用 - 相同的主機和端口?或者端口不同?如果是這樣,那麼這被視爲CORS,這意味着您的後端必須返回200 OK以進行「OPTIONS」調用,請檢查您的開發人員工具網絡選項卡,查看調用 – maurycy