我正在使用前端angularjs和beckend codeignitor(3)。我想在后端控制器中发布数据。但是我无法获取数据。
这是我的html-
<form>
<fieldset class="form-group">
<h3>Get data of your table</h3>
<label for="exampleInputPassword1">Select coloumn value</label>
<input type="text" class="form-control" ng-model="table.table_column" id="exampleInputPassword1" placeholder="table coloumn values">
<small class="text-muted">Please enter valid data.</small>
</fieldset>
<fieldset class="form-group">
<label for="exampleInputEmail1">Enter Table Name</label>
<input type="text" ng-model="table.table_name" class="form-control" id="exampleInputEmail1" placeholder="Enter Table Name">
<small class="text-muted">Please enter valid table name.</small>
</fieldset>
<fieldset class="form-group">
<label for="exampleInputPassword1">Where</label>
<input type="text" class="form-control" ng-model="table.table_where" id="exampleInputPassword1" placeholder="Where">
<small class="text-muted">Please enter valid value</small>
</fieldset>
<fieldset class="form-group">
<label for="exampleInputPassword1">Value</label>
<input type="text" class="form-control" ng-model="table.table_value" id="exampleInputPassword1" placeholder="Table Value">
<small class="text-muted">Please enter valid value</small>
</fieldset>
<button type="submit" class="btn btn-primary" ng-click="submitForm(table)">Submit</button>
</form>
</div>
这是我的angularjs控制器功能-
$scope.submitForm = function(table) {
$http.post("http://localhost/DatabaseApp/welcome/getData/",table)
.success(function(response) {$scope.data = response});
}
这是我的codeignitor函数-
function getData()
{
$table_column = $this->input->post('table_column');
$table_name = $this->input->post('table_name');
$table_value = $this->input->post('table_value');
$table_where = $this->input->post('table_where');
print_r($table_name);
}
因此,如果有人可以帮助我,我将不胜感激。非常感谢。
当然,您无法使用$ _POST数组获取数据,因为有角度的$ http以字符串流的形式发送请求数据,因此您应该使用:
$data = file_get_content("php//input");
$data = json_decode($data);
$table_column = $data->table_column;
$table_name = $data->table_name;
$table_value = $data->table_value;
$table_where = $data->table_where;
祝你好运
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句