【AngularJs】获取URL查询参数
<script> var app = angular.module('myApp', []); app.config(['$locationProvider', function ($locationProvider) { $locationProvider.html5Mode( { enabled: true, requireBase: false//必须配置为false,否则<base href=''>这种格式带base链接的地址才能解析 }); }]); app.controller('myCtrl', ['$scope', '$http', '$location', function ($scope, $http, $location) { $scope.supplierInfo = { id: $location.search().id } $scope.saveData = function () { if ($scope.supplierInfo.id) {//修改 alert($scope.supplierInfo.id) } else {//新增 var config = { headers: { 'Content-Type': 'application/json' } // transformRequest: function (obj) { // var str = []; // for (var p in obj) { // str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); // } // return str.join("&"); // } }; var data = { "name": $scope.supplierInfo.name, "remark": $scope.supplierInfo.remark } $http.post('http://localhost:8006/rest/littlecat/caobao/supplier/add', data, config) .then(function (result) { //正确请求成功时处理 window.location = 'SupplierList.html' }).catch(function (result) { //捕捉错误处理 console.log(result); }); } } }]); </script>
南京小黄猫教育
是专业的计算机编程培训,包含面向少儿的Scratch,面向青少年的Python,面向就业的Java、C/C++及Web前端技术。微信:wuwy233
地址:南京市江宁区月华路12-6弘阳上院