doumu9019 2015-10-10 20:07
浏览 37
已采纳

无法从AngularJS $ http.post获取发布数据

Very new with AngularJS, I'm sure it's something simple I'm doing wrong but I cannot figure it out. All I'm trying to do is log the incoming POST from Angular, using PHP.

AngularJS function:

$scope.addTask = function() {
        $http.post('process.php', { newTask: $scope.newTask });
        $scope.newTask = '';
    };

process.php:

if (isset($_POST['newTask'])) {
        createLog('test');
    }

function createLog ($str) {
    $file = 'log.txt';
    $str .= "
";
    file_put_contents($file, $str, FILE_APPEND | LOCK_EX);
}
  • 写回答

1条回答 默认 最新

  • dsn5510 2015-10-10 20:30
    关注

    If you are sending in a POST to PHP from angular, you need to retrieve it a bit differently in your backend. As noted by @charlietfl, the $_POST is empty. I have been out of the PHP game for a while but this should work for you.

    $data = file_get_contents("php://input");
    $request = json_decode($data);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas
  • ¥15 蓝牙硬件,可以用哪几种方法控制手机点击和滑动
  • ¥15 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题
  • ¥20 materialstudio计算氢键脚本问题