我试图将值从我的PHP表单传递到我的php文件。 我的html代码
<form>
<div class="form-group col-md-2">
<div class="form-group col-md-2">
<label for="EndDateSearch">Date range end date</label><br/>
<div class="sandbox-container" id="req_end_date">
<div class="input-group date form_datetime">
<input name="EndDateSearch" type="text" class="form-control" placeholder="Select date" ng-model="EndDateSearch">
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
</div>
<div class="input-group-btn form-group col-md-2">
<button ng-click="searchWr(EndDateSearch)" class="btn btn-default" type="submit"><b>SEARCH</b>
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
<form>
我的angularJs代码如果跟随
$scope.searchWr = function() {
$http.post("search_data.php", 'EndDateSearch': $scope.EndDateSearch
})
.success(function(myData) {
$scope.myRequestAlldata = myData;
});
};
我的search_data.php包含以下代码:
if(isset($data->EndDateSearch)){
echo $EndDateSearch=$data->EndDateSearch;
}
问题是,如果我从文本框中传递日期,它没有将任何值传递给search_data.php,除了日期工作正常。我的代码中有任何问题吗?
答案 0 :(得分:0)
你以错误的方式发送数据,$ http.post的第二个参数是一个对象,试着像这样重写你的函数:
$scope.searchWr = function() {
$http.post('search_data.php', {
'EndDateSearch': $scope.EndDateSearch
})
.success(function(myData) {
$scope.myRequestAlldata = myData;
});
};
请注意,第二个参数现在是一个对象。
答案 1 :(得分:0)
$scope.searchWr = function() {
$http.post("search_data.php", $("form").serialize())
.success(function(myData) {
$scope.myRequestAlldata = myData;
});
};