我正在通过angularjs发出发布请求。
<input class="form-control" ng-model="hotel.hotel_name" type="text">
<input class="form-control" ng-model="hotel.hotel_loc" type="text">
<input type="button" value="Submit" name="Submit" ng-click="addHotel(hotel)" class="btn btn-sm btn-primary">
控制器
$scope.addHotel=function(hotel){
$http({
method:"POST",
data:{'hotel':hotel},
url:base_url+'operator/hotel/add_hotel'
}).then(function serverResponse(response){
//clear the old form data
$scope.hotel=[];
})
}
数据处理成功后,清除旧表格数据 $scope.hotel=[]
但是当我重新提交带有一些值的表格时,它无法读取,我会得到 undefiend
$scope.addHotel=function(hotel){
//undefiend
console.log(hotel);
}
注意:第一次发布请求和响应是成功的,但此后不能执行
您正在设置hotel
为array
。您应该将其设置为object
。
$http({
method:"POST",
data:{'hotel':hotel},
url:base_url+'operator/hotel/add_hotel'
}).then(function serverResponse(response){
//clear the old form data
$scope.hotel={}; //this is what you should do
});
或将其设置为空字符串。
$scope.hotel.hotel_name = '';
$scope.hotel.hotel_loc = '';
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句