我有一段似乎没有发布的角度代码。 说实话,firefox显示了发布参数,但是当我在服务器上执行print_r($ _ POST)并通过firefox查看响应时,我显示一个空数组。
以下是代码段。
$http({
method: 'POST',
data : { slotid : slotid },
url: "https://mydomain.abc/Api/reserve_slot/" + slotid + "/" + $scope.docid,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response) {
$scope.r = response.data.list;
console.log($scope.r);
if($scope.r.status == 1){
$scope.hide();
$state.go('booking', { slotid: slotid });
}
});
正在调用网址。因为如果我附加要通过它们工作的URL传递的变量/值(显然)。 我只是不知道帖子为什么不起作用。
我已经过测试,data : { slotid : slotid },
在slotid中有值。
有什么想法吗?
- - - - 编辑 下面是完整的控制器代码。
.controller('doctorCtrl', ['$scope', '$stateParams', '$http', '$ionicLoading', '$state', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams, $http, $ionicLoading, $state ) {
$scope.docid = $stateParams.docid;
$scope.show = function() {
$ionicLoading.show({
content: 'Loading',
showBackdrop: false,
animation: 'fade-in',
}).then(function(){
console.log("The loading indicator is now displayed");
});
};
$scope.hide = function(){
$ionicLoading.hide().then(function(){
console.log("The loading indicator is now hidden");
});
};
$scope.show();
$http({
method: 'POST',
url: "https://mydomain.abc/Api/docinfo",
data : { docid : $scope.docid },
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response) {
$scope.docinfo = response.data.info;
console.log($scope.docinfo);
$scope.loadslots($scope.docid,0);
//return response.data.list;
});
$scope.loadslots = function(docid,dinaya){
$http({
method: 'GET',
url: "https://mydomain.abc/Api/get_slots/" + docid + "/" + dinaya,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response) {
$scope.slots = response.data.list;
console.log($scope.slots);
$scope.hide();
});
}
$scope.showslot = function(slotid){
$scope.show();
//data: $.param({slotid: slotid})
$http({
method: 'POST',
//data : { slotid : slotid },
//data: $.param({slotid: slotid}),
url: "https://mydomain.abc/Api/reserve_slot/" + slotid + "/" + $scope.docid,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response) {
$scope.r = response.data.list;
console.log($scope.r);
if($scope.r.status == 1){
$scope.hide();
$state.go('booking', { slotid: slotid, docid: $scope.docid });
}
});
}
}])
我正在尝试构建一个离子1 app.Haven添加了jquery。
添加Codeigniter控制器。
public function reserve_slot(){
/*
print_r($_POST); //shows me an empty array
$slot = $this->input->post('slotid); //no data here
$doc = $this->input->post('doc'); //no data here
*/
$slot = $this->uri->segment(3);
$doc = $this->uri->segment(4);
$this->load->model('Doctor');
$this->Doctor->reserve_slot($slot);
$list['status'] = 1;
$data['list']= $list;
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Content-Type: application/json');
echo json_encode($data);
}
答案 0 :(得分:0)
在查询中,$ .param会产生类似的角色。
下面的代码完成了帖子。
$scope.showslot = function(slotid){
$scope.show();
//data: $.param({slotid: slotid})
var pdata = { slotid : slotid , docid : $scope.docid};
$http({
method: 'POST',
//data : { slotid : slotid },
data: $httpParamSerializerJQLike(pdata),
url: "https://mydomain.abc/Api/reserve_slot/" + slotid + "/" + $scope.docid,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response) {
$scope.r = response.data.list;
console.log($scope.r);
if($scope.r.status == 1){
$scope.hide();
$state.go('booking', { slotid: slotid, docid: $scope.docid });
}
});
}