我正在构建一个 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 的问题。
我正在寻找有关这样做的优点的输入。
谢谢。