• home > webfront > ECMAS > angularjs >

    angularjs用$http发起ajax请求,提交JSON数据post后台无法接收

    Author:[email protected] Date:

    angularjs用$http发起ajax请求,提交JSON数据post后台无法接收但是,后台无法接受,是 ,Request playload,不是 formData怎么调试都无


    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("&");
                };


    Screen Shot 2016-07-07 at 19.41.03.png


    转载本站文章《angularjs用$http发起ajax请求,提交JSON数据post后台无法接收》,
    请注明出处:https://www.zhoulujun.cn/html/webfront/ECMAScript/angularjs/2016_0707_7853.html