Angularjs Http服务POST 500内部服务器错误

时间:2016-10-17 08:25:29

标签: javascript php angularjs httpservice

嗨,我是角度js的新手,我正在尝试在角度js中创建CRUD操作。但我遇到了POST错误,当我从表单发布时,它会告诉500内部服务器错误。

我的控制器代码:

 public function index_post(){
 $bookId = $this->API_model->insert_entery($_POST);
if(! is_null($bookId)){
    $this->response(array("response" => $bookId),200);
 }

else{
        $this->response(array("error" =>"coudn't post"),400);
    }
    echo $this->db->last_query();
}

我的模特:       API_model

     public function insert_entery($options=array())
        {
      if(isset($options["book_name"])){
        $this-> db -> set("book_name",$options["book_name"]);
    }

    if(isset($options["book_price"])){
        $this-> db -> set("book_price",$options["book_price"]);
    }

    if(isset($options["book_author"])){
        $this-> db -> set("book_author",$options["book_author"]);
    }
    return $this-> db->insert('books');
}

我的观点:

 <div ng-app="myApp" ng-controller="cntrl">
 <form>
   Book name <input type="text" ng-model="book_name" name="book_name"    ng-disabled="obj.idisable">
 Book price: <input type="text" ng-model="book_price" name="book_price">
 Book author: <input type="text" ng-model="book_author" name="book_author">
 <input type="button"  ng-click="insertdata()" >
 {{msg}}

 </form>

 </div>
 <script>
var app=angular.module('myApp',[]);
app.controller('cntrl', function($scope,$http){
$scope.obj={'idisable':false};
$scope.btnName="Insert";

$scope.insertdata=function(){
$http.post("/books",{'book_name':$scope.book_name,   'book_price':$scope.book_price
        ,'book_author':$scope.book_author
})
    .success(function(){
        $scope.msg="Data Inserted";


    })

}
});
</script>

0 个答案:

没有答案