0

我正在构建一个 API 来接收 POST 数据并在 Ruby on Rails 3 中返回 JSON。我正在使用 angularjs $http 对象提交数据。

var post_data = {
    content: $scope.post_content,
    authentication_token: csrf
};

$http({
    url: feed_endpoint,
    method: "POST",
    'Content-Type': 'application/json',
    params: post_data
    }).success(function(post_data, status, headers, config) {

    }).error(function(post_data, status, headers, config) {
        $scope.status = status;
    });
}

引号等的转义适用于这种方法,我在将 js 数据对象(哈希)传递给 $http.data 对象时遇到了错误创建 JSON 的问题。

我正在寻找有关这样做的优点的输入。

谢谢。

4

1 回答 1

1

尝试使用 $http.post,这种形式对我有用。

$http.post(feed_endpoint, post_data, {"Authorization": ""})
    .success(function(response) {...}
于 2013-10-08T22:38:20.160 回答