Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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 如何在AngularJS中使用$http或$resource发送包含JSON数据的POST请求?_Node.js_Angularjs_Express_Angularjs Directive_Angularjs Resource - Fatal编程技术网

Node.js 如何在AngularJS中使用$http或$resource发送包含JSON数据的POST请求?

Node.js 如何在AngularJS中使用$http或$resource发送包含JSON数据的POST请求?,node.js,angularjs,express,angularjs-directive,angularjs-resource,Node.js,Angularjs,Express,Angularjs Directive,Angularjs Resource,我想用postData(JSON) 我尝试了以下$http请求 var jsonData={“id”:1, “名称”:“xxx”, “指定”:“开发商”, “部门”:“IT”} $http({method: 'POST', url: url, data: jsonData, headers: {'contentType': 'application/json'} }).success(function() {

我想用postData
(JSON)

我尝试了以下
$http
请求

var jsonData={“id”:1, “名称”:“xxx”, “指定”:“开发商”, “部门”:“IT”}

$http({method: 'POST',
            url: url,
            data: jsonData,
            headers: {'contentType': 'application/json'}
        }).success(function() {
            $scope.sucess = "Success";
        }).error(function() {
            $scope.errorMessage = "Failure";
        });

但由于$http和$resource请求的输入结束错误,“没有要映射到对象的内容

其他信息:*
我的客户端应用程序正在使用node.js的Express serve上运行
*
有谁能帮我用上述任何一种方法实现这一点吗?

您正在使用的服务器端框架是什么?我认为问题在于您的框架的对象映射器(或一些进行对象映射的机制,如ASP.NET MVC中的机制)没有完全工作。简而言之,我不认为问题出在AngularJS和您的客户端框架上。您的jsonData是什么样子的?是对象还是字符串?如果是对象,您不需要添加任何标题。Angular默认将对象序列化为JSON并添加正确的标题。如果可能,请发布完整的内容原始HTTP请求的nt,因为您得到的错误是服务器端错误,所以您的请求必须发送无效的JSON,或者您的服务器未正确配置为反序列化。Kia Panahi:我的服务器端是EJB。dtabuenc:我的JSON是一个对象而不是stringdtabuenc:请参阅上面我的更新问题和我的JSON样本数据
$resource('/path/to/the/server',{},{update:{method: 'POST', headers: 
{'Content-Type': 'application/json'}}});