我正在尝试发送用户放入文本区域的数据和文本输入以及将保存数据的 API。
这是函数:
$scope.forward = function() {
$http({
url: 'http://appsdev.pccportal.com:8080/ecar/api/reject/' + carID,
method: "POST",
data: "comments=" + this.comments,
data: "recipient=" + this.recipient,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).
then(function(response) {
$scope.output = response.data;
})
}
它运行时的作用是仅记录收件人而不记录评论。我猜测是因为我使用了“数据”两次,并且它只识别最后一个(在本例中为“接收者”)。我如何通过它向 API 传递 2 个值。
谢谢
最佳答案
正如您所说,您将覆盖传递给 $http
的普通对象中的 data
键,将其全部发送:
data: { recipient: this.recipient, comments: this.comments }
关于javascript - AngularJS - 将数据发布到 API 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39007474/