发布请求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