angular常见问题

1、angular $http服务post提交数据到php,php无法_post到数据。
var order = angular.module("order",[]).config(function($httpProvider){
    $httpProvider.defaults.transformRequest=function(obj){
        var str=[];
        for(var p in obj){
            str.push(encodeURIComponent(p)+"="+encodeURIComponent(obj[p]));
        }
        return str.join("&");
    };

    $httpProvider.defaults.headers.post={
        'Content-Type':'application/x-www-form-urlencoded'
    };
});

$http({
    url:"/index.php",
    methods:"POST",
    data:{name:"张德帅",age:"18"}
}).success(function(res){
    console.log(res);
});
2、angular $location服务开启html5Mode
var order = angular.module('order',[]);
order.config(function($locationProvider){  
  $locationProvider.html5Mode(true).hashPrefix('!');
}).controller('order',function($scope,$http,$location){
     $scope.url = $location.search();
});

再到对应的head添加

你可能感兴趣的:(angular常见问题)