var send=[];
// send[] data contains:
// [{"host":"1","name":"2","password":"3"},
// {"host":"4","name":"5","password":"6"},
// {"host":"7","name":"8","password":"9"},
// {"host":"10","name":"11","password":"12"}]
$http({
method: 'POST',
url: 'file.php',
data: send,
headers: {
'Content-Type': 'Content-type: application/json'
},
}).
success(function(response) {}).
error(function(response) {});
return false;
};
发送数据时出现错误,我无法使用$ _POST解析此数据。我尝试过以下操作:
var obj=(JSON.stringify(send));
data:obj,
并在我的PHP文件中:
$request = file_get_contents('php://input');
$data=json_decode($request);
print_r($data);
答案 0 :(得分:0)
如果您想要检索发布的数据,请使用$_POST['data']
:
$request = $_POST['data'];
$data = json_decode($request);
print_r($data);
你能否详细说明你的意思"我收到错误"?