發佈請求url應該按照以下格式進行更新。通過工廠在Angular 1.x中發送發佈請求
https://www.example.com/api/one-push?type=json&query=push&title=____&url=____&tag=___
<form ng-submit="submitUrl()">
<input type="text" class="form-control block" ng-model="url.title" placeholder="title">
<input type="text" class="form-control block" ng-model="url.urlString" placeholder="url">
<input type="text" class="form-control block" ng-model="url.tag" placeholder="tag">
<button>Add</button>
</form>
var app = angular.module('app', [])
.controller('searchController', ['$scope', '$http','searchService', function($scope, $http,searchService) {
$scope.submitUrl = function() {
$scope.url = {};
searchService.updateUrl($scope.url).success(function(data) {
$scope.url = data;
})
}
}]);
app.factory('searchService',function($http) {
var url = " https://www.example.com/api/one-push?";
var Info = {};
Info.updateUrl = function(url) {
return $http.post(url, {
type: "json",
url: url.title,
urlString: url.urlString,
tag: url.tag
});
}
return Info;
});
感謝您的回答。另一種修正替換URL以_data和它的工作PARAMS:{ 類型: 「JSON」, 網址:_data.urlString, 查詢: '推', 標題:_data.title, 標籤:_data.tag } – rebello