According to the answers to previous questions about posting data back to a server API with Angular, you need to post the data as a plain-text string instead of as Json.
However, I am thinking that there is a built-in function within the Moodle library that already deals with Json posted to it, in which case I should just be able to send Json. Is that correct?
And if it is correct, should I url-encode my Json string?
This is my function so far, which is inside my controller.
myApp.controller('mydataCtrl', function ($scope, $http) {
url = concatUrl + 'local_webservice_ws_get_mydata'; // GET
updateUrl = concatUrl + 'local_webservice_ws_set_mydata'; // SET
$http.get(url).then(function (response) {
$scope.mydata = response.data;
});
$scope.sendmypost = function () {
// Writing it to the server
$http.post(updateUrl, $scope.mydata).then(function (response) {
// Success
$scope.server_response = [
{ 'message':'Your settings have been updated' }
];
}, function (response) {
// Error
$scope.server_response = [
{ 'message':'Unexpected error' }
];
});
}
});