解决angularJs使用POST请求时服务器端不能接受到数据

$http({
      url:'data/order_add.php',
      method:'POST',
      data:{
        user_name:$scope.user_name,
         sex:$scope.sex,
        phone:$scope.phone,
        addr:$scope.addr,
        did:$location.search().did
      },
      headers:{'Content-Type':'application/x-www-form-urlencoded'},
      transformRequest:function(obj){
         var str=[];
        for(var p in obj){
          str.push(encodeURIComponent(p)+"="+encodeURIComponent(obj[p]));
          }
        return str.join("&");
         }
    }).success(function(data){
      alert("状态:" + data.status + "您的订单编号为:" + data.oid);
    }).error(function(){
      alert("状态:" + data.status + "原因:" + data.msg)
    })
}

 

posted @ 2018-06-01 16:58  mchtig  阅读(272)  评论(0编辑  收藏  举报