2017-03-09 17 views
0

エラーJS角度ポストデータ

angular.js:14362 TypeError: $http.post(...).success is not a function at ChildScope.$scope.insertData (myjs.js:6) at fn (eval at compile (angular.js:15197), :4:150) at callback (angular.js:26808) at ChildScope.$eval (angular.js:18017) at ChildScope.$apply (angular.js:18117) at HTMLButtonElement. (angular.js:26813) at defaultHandlerWrapper (angular.js:3617) at HTMLButtonElement.eventHandler (angular.js:3605)

htmlページ:

<body ng-app="mymod">  
     <div class="container" ng-controller="mycontroller"> 
     <div class="main-head"> 
     <img src="img/main.jpg" class="img img-thumbnail" alt="main image"> 

      </div> 
     <div class="row"> 
    <div class="col-sm-5"> 

     <form> 



    <div class="form-group"> 
    <label for="firstname">First name</label> 
    <input type="text" class="form-control" id="firstname" ng-model="firstname" name="firstname"> 
    </div> 


    <div class="form-group"> 
    <label for="lastname">Last Name</label> 
    <input type="text" class="form-control" id="lastname" ng-model="lastname" name="lastname"> 
    </div> 



    <div class="form-group"> 
    <label for="district">District</label> 
    <input type="text" class="form-control" id="district" ng-model="district" name="district"> 
    </div> 


    <div class="form-group"> 
    <label for="dateofborth">Date Of Birth</label> 
    <input type="text" class="form-control" id="datepicker" ng-model="dob" name="dob"> 
    </div> 


     <button type="submit" ng-click="insertData()" class="btn btn-info btn-sm"> Submit</button>  

     </form>         

      </div> 


       <div class="col-sm-6 col-sm-offset-1 right">           <table class="table table-condensed"> 

        <thead> 
         <tr> 
         <th> First Name</th> 
         <th> Last Name</th> 
         <th> District</th> 
         <th> Date Of Birth</th> 
         </tr> 
        </thead> 
        <tbody> 
        <tr ng-repeat="student in data"> 
         <td>{{ student.firstname }}</td> 
         <td>{{ student.lastname }}</td> 
         <td>{{ student.district }}</td> 
         <td>{{ student.dob }}</td> 

        </tr> 
        </tbody> 


       </table> 

Insert.phpページは

include('connectdb.php'); 


$data = json_decode(file_get_contents("php://input")); 

$firstname = $dbhandle->real_escape_string($data->firstname); 
$lastname = $dbhandle->real_escape_string($data->lastname); 
$district = $dbhandle->real_escape_string($data->district); 
$dob = $dbhandle->real_escape_string($data->dob); 



$query = "INSERT INTO students VALUES($id,'".$firstname."','".$lastname."','".$district."','".$dob."')"; 


$dbhandle->query($query); 

jsがファイル

10は私がエラー:( 私はこのお試しください

答えて

0

私のDBのデータ送信したい見つける傾ける私を助けてください:

$scope.insertData = function($http){ 
    $http.post("insert.php",{'firstname':$scope.firstname,'lastname':$scope.lastname,'district':$scope.district,'dob':$scope.dob}) 
    .success(function(){  
     $scope.msg = "Data Submitted"; 

    }) 
} 
+0

が動作しない:(例外TypeError:。ChildScope $ scope.insertData(myjs.jsで未定義 のプロパティ 'ポスト' を読み込めません:コンパイル時5)FNで (evalの(angular.js:15197)、:4 26808)ChildScopeの$ evalの(angular.jsで ::。:コールバック(angular.jsで150) 。18017)ChildScopeで $適用されます(angular.js:18117) HTMLButtonElementで(angular.js:26813 ) at defaultHandlerWrapper(angular.js:3617) at HTMLButtonElement.eventHandler(angular.js:3605) – boy90

+0

あなたの$ httpは定義されていないようです。 – sfratini

0

この$のHTTPハンドラで試してみてください -

$http.post('/someUrl', data, config).then(function(res){ 
    // The Code Here which runs on success callback 
    }, function(err){ 
     // The Code Here which runs on Error callback 
}); 

をそれHttpPromiseを返します。