- POST
- OPTIONS
$http POST, OPTIONS requests
remove examples/mojo_ajax/items.db
$ sqlite3 examples/mojo_ajax/items.db
examples/d2/angular_v2_add_item.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes"> <script src="../angular/angular.min.js"></script> <script src="angular_v2_add_item.js"></script> <link rel="stylesheet" href="style.css" type="text/css" media="print, projection, screen" /> <title>List items</title> </head> <body> <script> </script> <div ng-app="DemoApp" ng-controller="DemoController"> <input ng-model="text"><button ng-click="add_item()">Add</button> <div id="error" ng-show="error">{{error}}</div> </div> </body> </html>
examples/d2/angular_v2_add_item.js
angular.module("DemoApp", []) .controller("DemoController", ['$scope', '$http', function($scope, $http) { $scope.add_item = function() { $scope.error = ''; $http.post('http://127.0.0.1:3000/api/v2/item', {text: $scope.text} ).then( function(response) { console.log(response); $scope.result = response.data; //console.log($scope.items); }, function(response) { console.log("error", response); $scope.error = response.data.text; } ); $scope.text = ''; } $scope.error = ''; }]);