gpt4 book ai didi

javascript - AngularJS - 错误正文请求 POST

转载 作者:行者123 更新时间:2023-12-02 15:13:21 26 4
gpt4 key购买 nike

我是 AngularJs 的新手,我需要使用枚举形式在服务器上执行发布请求。我在 JS 中这样做:

function completeTaskAction2($scope, $http, Base64) {
$http.defaults.headers.common['Authorization'] = 'Basic ' + Base64.encode('kermit' + ':' + 'kermit');
$http.get("http://localhost:8080/activiti-rest/service/runtime/tasks")
.then(function (response, data, status, headers, config) {
var ids = response.data.data[0].id;

$scope.formData2 = {
taskId: ids,
properties: [{
id: 'requestApproval',
value: ''
}
]
}
});
$scope.submitForm2 = function () {

$http({
method: 'POST',
url: "http://localhost:8080/activiti-rest/service/form/form-data",
data: angular.toJson($scope.formData2),
headers: {
'Authorization': 'Basic ' + Base64.encode('kermit' + ':' + 'kermit'),
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).success(function (data) {

console.log("OK", data);
}).error(function (data) {

console.log("Error Posting data...");
console.log(data);
console.log($scope.submitForm2);
});
};

};

在 html 中:

 <div ng-controller="completeTaskAction2">
<div ng-repeat="x in names">
{{ x.name }}*

<form ng-submit="submitForm2()">
<a ng-if="x.type=='enum'">
<select ng-model="formData2.properties[0].value" ng-options="y.name for y in x.enumValues " placeholder="{{ x.name[0] }}"> {{ x.name }} </select>
</a>
<br>

<button type="submit" class="btn btn-success btn-lg btn-block">
<span class="glyphicon glyphicon-flash"></span> Submit Enum!
</button>
</div>


</div>
</form>

但我有这个错误:

Could not read JSON: Can not deserialize instance …

响应正文是:

{"taskId":"67762","properties":[{"id":"requestApproval","value":{"id":"true","name":"Yes"}}]}

我只需将其发送到服务器:

**{"taskId":"67762","properties":[{"id":"requestApproval","value":"true"}}]**

我怎样才能做到这一点?

最佳答案

你的 ng-options 应该是这样的:

ng-options="y.id as y.name for y in x.enumValues"

这会将 y 的 id 绑定(bind)到模型值,而不是整个 y 对象。

关于javascript - AngularJS - 错误正文请求 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34654288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com