這裏是我的AngularJS代碼發出請求:POST請求是有效的(狀態200),但未能滿足條件
$scope.add = function(){ // Function used to add a value to list. Value has name, type, and priority.
if($scope.thing){
$scope.items.push(
{name: $scope.thing,
type: $scope.worktypeSelection,
priority: $scope.prioritySelection,
completed: false,
comments: '',
creator: $scope.username,
assignedTo: $scope.assign
});
var itemToJson = $scope.items[$scope.items.length - 1];
$http.post('http://localhost:8080/server/todoList/addItem', {itemToJson})
.success(function(response) {alert("success");})
.error(function(response) {alert("fail");});
$scope.thing = '';
}
else{
alert("Empty task is not allowed!");
}
};
而且我的Grails控制器:
package server
import grails.converters.JSON
class TodoListController {
def addItem() {
def newItem = new Item(request.JSON)
newItem.save(flush: true)
render newItem as JSON
}
def index(){
render Item.list() as JSON
}
}
而且其領域類:
package server
class Item {
String name
String type
String priority
boolean completed = false
String comments
String creator
String assignedTo
static constraints = {
name nullable: false
priority nullable: true
type nullable: true
comments nullable: true
creator nullable: false
assignedTo nullable: false
}
}
當我開始後,我收到了200從網絡(據稱意味着職位是好的),但後來我得到的輝l結果(警報彈出「失敗」)。我不明白的問題是什麼,如果請求實際上到達服務器
非常感謝您的支持,但這並沒有解決問題。雖然很高興知道! – Ajv2324