angularjs用$http发起ajax请求,提交JSON数据post后台无法接收
Author:[email protected] Date:
angularjs用$http发起ajax请求,提交JSON数据post后台无法接收
但是,后台无法接受,是 ,Request playload,不是 formData
怎么调试都无效,后来发现,……
在请求头 ,添加表单格式,即:
Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8
.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', function ($stateProvider, $urlRouterProvider, $httpProvider) { /* 我的拦截器 */ $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; $httpProvider.defaults.transformRequest = function (obj) { var str = []; for (var p in obj) str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); return str.join("&"); };
转载本站文章《angularjs用$http发起ajax请求,提交JSON数据post后台无法接收》,
请注明出处:https://www.zhoulujun.cn/html/webfront/ECMAScript/angularjs/2016_0707_7853.html