我尝试将带有$http的帖子发送到php,它运行良好,但是当我想测试$_post['操作'] =='getPayments'时,这不会什么也没回应。
这是我$http帖子:
var req = {
method: 'POST',
url: 'process.php',
headers: {
'Content-Type': 'json'
},
data: 'action=getPayments'
}
$http(req).then(function(req){
console.log(req.data);
$scope.bidslist = req.data;
}, function(){
});
这是php:
$action = isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '');
if ( !empty($action) ) {
switch ( $action ) {
case 'getPayments':
some code goes here
echo json_encode($myArray);
break;
}
}
我可以在调试控制台中看到这个带有 action=getPayments 的发送帖子,但在 php 方面,它不会重新识别帖子,只有当我删除开关它的工作时。
我没有任何错误,只是没有来自 php 的响应是什么问题?
尝试将内容类型设置为应用程序/json
var req = {
method: 'POST',
url: 'process.php',
headers: {
'Content-Type': 'application/json'
},
data: 'action=getPayments'
}
$http(req).then(function(req){
console.log(req.data);
$scope.bidslist = req.data;
}, function(){
});
数据必须是对象有效载荷,
var data = {action: getPayments(what's this?)};
var req = {
method: 'POST',
url: 'process.php',
data: data
}
$http(req).then(function(req){
console.log(req.data);
$scope.bidslist = req.data;
}, function(){
});