小编Ash*_*war的帖子

$ http.post在AngularJS中不起作用

当我使用$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)

javascript php jquery angularjs

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

angularjs ×1

javascript ×1

jquery ×1

php ×1