angularjs - Using Angular to post data to Moodle API -
according answers previous questions posting data server api angular, need post data plain-text string instead of json.
however, thinking there built-in function within moodle library deals json posted it, in case should able send json. correct?
and if is correct, should url-encode json string?
this function far, inside controller.
myapp.controller('mydatactrl', function ($scope, $http) { url = concaturl + 'local_webservice_ws_get_mydata'; // updateurl = concaturl + 'local_webservice_ws_set_mydata'; // set $http.get(url).then(function (response) { $scope.mydata = response.data; }); $scope.sendmypost = function () { // writing 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' } ]; }); } });
i found brilliant tutorial submit angular data server , return response.
$http.post server request in angularjs how send data server using httppost method in angularjs
and if using checkbox change data on server, need stack overflow post how bind checkbox model. answer zsong worked me.
Comments
Post a Comment