Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json在$http post中的处理_Json_Angularjs_Http_Express_Server - Fatal编程技术网

Json在$http post中的处理

Json在$http post中的处理,json,angularjs,http,express,server,Json,Angularjs,Http,Express,Server,我试图使用$http将json数据发布到express服务器 $scope.createTravel = function(){ $http({ url: '/api/travels', method:"POST", data: $scope.formData // headers: {'Content-Type': 'application/json'} }) }; post正在此控制台日志语句中

我试图使用$http将json数据发布到express服务器

$scope.createTravel = function(){

       $http({
        url: '/api/travels',
        method:"POST",
        data: $scope.formData
        // headers: {'Content-Type': 'application/json'}
       })

};
post正在此控制台日志语句中到达服务器

app.post("/api/travels", function(req, res){

    console.log(req);

});

没有json数据。

开始调查。第一步:这是一个角度问题还是一个表达问题?将$scope.data打印到控制台时会发生什么情况?如果将$scope.data替换为{foo:'bar},会发生什么情况?当您打开浏览器开发工具并在网络选项卡中检查发送的请求时,请求是否具有您期望的正文?尝试打印console.logreq.body.data;