$http.post方式提交的数据格式为:
{‘params1′:’params1’, ‘params2′:’params2’}
而ajax.post提交格式为:
params1=params1¶ms2=params2
所以服务端无法获取到参数。只需要设置全局参数即可:
app.config(function($httpProvider){ $httpProvider.defaults.transformRequest = function (obj) { var str = []; for (var p in obj) { str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); } return str.join("&"); }; $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; });