开发者社区> 问答> 正文

PHP怎么获取获取angularjs http.post?

前端:

$http({
method: 'POST',
url: "http://127.0.0.1:8080/school/studentadd.php",
data : newnames,
headers : {'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function(){
console.log('success');
}).error(function(){
alert("error");
});

PHP接收:echo file_get_contents('php://input'); 没显示任何数据
图片说明
screenshot
这是什么原因,没获取到数据吗?

展开
收起
小旋风柴进 2016-03-10 09:31:38 2285 0
1 条回答
写回答
取消 提交回答
  • $http.post获得的返回不是个json么?取callback的success方法返回值就可以啊。
    $http({
    method : 'POST',
    url : 地址,
    data: 数据
    }).success(function(data, status, headers, config) {
    console.log(data);
    }).error(function(data, status, headers, config) {
    
    });

    把data赋给你的变量,log一下需要那个字段就显示那个字段好了。

    2019-07-17 18:56:49
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-直面PHP微服务架构挑战-高驰涛 立即下载
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载