Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.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
Node.js 角度$http.post->Express:停止将数字转换为字符串_Node.js_Angularjs_Express - Fatal编程技术网

Node.js 角度$http.post->Express:停止将数字转换为字符串

Node.js 角度$http.post->Express:停止将数字转换为字符串,node.js,angularjs,express,Node.js,Angularjs,Express,我正在尝试发送数据$scope.resto是我表单中所有输入字段的模型,从angular到Expression都使用它 console.log($scope.resto); $http({ method: 'POST', url: '/new', contentType: 'application/json', params: $scope.resto.... $scope.resto是一个具有各种字符串和数值的对象。在服务器端 app.post

我正在尝试发送数据$scope.resto是我表单中所有输入字段的模型,从angular到Expression都使用它

console.log($scope.resto);
$http({
    method: 'POST',
    url: '/new',
            contentType: 'application/json',
    params: $scope.resto....
$scope.resto是一个具有各种字符串和数值的对象。在服务器端

app.post '/new', express.bodyParser(), (req, res) ->
    data = req.query
我尝试使用JSON.stringify$scope.resto,但结果是req.query req.body是一个空对象,它是一个以整数为键的对象,每个字段都只是JSON字符串中的一个字符。这是完全无法使用,但我不知道我做错了什么。很高兴添加更多的代码片段,但这些都是基础


当我向客户端发送数据时,保存数值没有问题

您将表单数据作为查询参数发送,但使用POST方法。您是否尝试过使用数据而不是参数?params通常用于GET请求

$http({
   method: 'POST',
   url: '/new',
   contentType: 'application/json',
   data: $scope.resto //Assuming $scope.resto contains an object with simple key:value pairs
});
从我发现的情况来看,通过POST发送参数应该会导致在请求主体中添加参数,但是如果看到您可能发送了一个{…},它的反应可能会很奇怪


我的最佳尝试是,如果这不能解决问题,您必须提供更多的上下文。

您在帖子中发送的数据可能没有初始化。你可以发布更多的控制器代码吗?你可以打开chrome开发者工具逐行浏览你的代码。