angular$http.post后台不能获取参数的问题

来源:互联网 发布:stussy淘宝 编辑:程序博客网 时间:2024/06/05 09:56

angular的http服务封装得并不完善,最好是自己做一个简单的封装

tempModule.factory('httpServer', function($http,$q) {    var service = {};    service.post = function (url,params,callback) {        var transform = function(data){            return $.param(data);        };        $http.post(url,params,{            headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},            transformRequest: transform        }).        success(callback);    };    return service;});

使用时:

tempModule.controller("settingCtrl", ["$scope",'httpService', function ($scope,httpService) {  httpService.post(url,params,function(data){    //这里写你要做的事    })}]);
0 0