var app = angular.module("app",["ngRoute"]);
app.controller("ctrl",function($scope,$http)
{
$http({
method:"POST",
url:"./json.php",
data:{time:123456}
}).success(function(data,status)
{
console.log(data);
})
});
PHP:
<?php
$time = $_POST['time'];
echo <<<EOF
{"a":"hello","time":"$time"}
EOF;
angular 不是用data作为POST参数吗?
为什么PHP接收不到这个参数?
angularjs默认情况下使用{'Content-Type' : 'application/json'}方式POST请求;
要确定下PHP设置默认接收POST请求的设置是不是这样的,用jQuery的时候POST请求的{'Content-TYpe':'application/x-www-form-urlencoded'}。如果是这个问题,可以设置angularJs的默认配置,
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;';