I am a beginner in AngularJs and I am trying to make a post request to a server with enum form. Currently, I have the following JavaScript code:
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);
});
};
};
In the HTML file:
<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>
However, I am encountering this error:
Could not read JSON: Can not deserialize instance …
The response body is:
{"taskId":"67762","properties":[{"id":"requestApproval","value":{"id":"true","name":"Yes"}}]}
I only want to send this data to the server:
**{"taskId":"67762","properties":[{"id":"requestApproval","value":"true"}]}**
Can anyone help me fix this issue?