angularjs post 后台 取不到值,修改contentTye 可以解决

前端之家收集整理的这篇文章主要介绍了angularjs post 后台 取不到值,修改contentTye 可以解决前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. var app = angular.module('maplePointApp',[]);
  2. app.config(["$httpProvider",function ($httpProvider) {
  3.     //更改 Content-Type
  4.     $httpProvider.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded;charset=utf-8";
  5.     $httpProvider.defaults.headers.post["Accept"] = "*/*";
  6.     $httpProvider.defaults.transformRequest = function (data) {
  7.         //JSON数据转换成字符串形式
  8.         if (data !== undefined) {
  9.             return $.param(data);
  10.         }
  11.         return data;
  12.     };
  13. }])
  14. app.controller('myCtr',function($scope,$http) {
  15.     $scope.initIndex = function () {
  16.         $http({
  17.             method : "post",            url : "${REQ}/maple/point",            data : {
  18.                 "id" : 123
  19.             }
  20.         }).success(function(rs) {
  21.             console.log(rs)
  22.             $scope.dataList=rs;
  23.         }).error(function(rs) {
  24.         });
  25.     }
  26. });

猜你在找的Angularjs相关文章