当我使用$http.get我的代码工作,但如果我使用$ http.post,我永远不会得到请求.php文件的参数.
这是服务功能:
TestPanel.service('MySampleService', function ($http, $q) {
this.getAllPosts = function () {
var def = $q.defer();
$http.post('/data/AJAXRequest.php', 'mydata=1&abcd=2').success(function (data) {
if (data == null)
def.reject('ERROR: DATA IS NULL');
else if (data.HasError)
def.reject('ERROR: ' + data.Message);
else
def.resolve(data);
}).error(function () {
def.reject('ERROR: Sorry, unable to complete your request.');
});
return def.promise;
}
});
Run Code Online (Sandbox Code Playgroud)
和控制器功能:
TestController.controller('PostCtrl', ['$scope', '$http', 'MySampleService',
function ($scope, $http, MySampleService) {
function FetchPostsList() {
MySampleService.getAllPosts().then(function (data) {
$scope.lstPosts = data.ResponseData;
$scope.totalRecords = data.totalRecords;
console.info('DATA=' + $scope.lstPosts); …Run Code Online (Sandbox Code Playgroud)