Angularjs $http.post

Posted ilinux_one

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Angularjs $http.post相关的知识,希望对你有一定的参考价值。

  $http.post 采用postJSON方式发送数据到后台.

  如果不需要发送json格式数据,序列化成&连接的字符串,形如:"a=1&b=2",最终完整的前端解决方案:

var url = ‘Gulugulus/setMenu‘,
            data = {
                menu: JSON.stringify(menu),
                test: ‘a String‘
            },
            transFn = function(data) {
                return $.param(data);
            },
            postCfg = {
                headers: { ‘Content-Type‘: ‘application/x-www-form-urlencoded; charset=UTF-8‘},
                transformRequest: transFn
            };

        $http.post(url, data, postCfg)
            .success(function(){
                window.location.href = "Gulugulus/subMenu";
            });

 

AngularJS中的$http.post与jQuery.post的区别

jQuery会把作为JSON对象的myData序列化,angularjs 以postJSON方式发送数据到后台.

以上是关于Angularjs $http.post的主要内容,如果未能解决你的问题,请参考以下文章