且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular JS POST 请求不发送 JSON 数据

更新时间:2023-01-17 08:08:32

如果您正在序列化您的数据对象,它将不是一个正确的 json 对象.拿走你所拥有的,然后将数据对象包装在 JSON.stringify() 中.

If you are serializing your data object, it will not be a proper json object. Take what you have, and just wrap the data object in a JSON.stringify().

$http({
    url: '/user_to_itsr',
    method: "POST",
    data: JSON.stringify({application:app, from:d1, to:d2}),
    headers: {'Content-Type': 'application/json'}
}).success(function (data, status, headers, config) {
    $scope.users = data.users; // assign  $scope.persons here as promise is resolved here 
}).error(function (data, status, headers, config) {
    $scope.status = status + ' ' + headers;
});