在开发一个angular项目时,发现$http的post请求有2种不同的形式。分为包括文件的表单与纯文本框的表单。
1.有文件上传的表单:
$http.post(saveUrl, formdata, {
headers: {'Content-Type':undefined},
transformRequest: angular.identity
}).success(function(responseData) {
console.log(responseData)
};
2.纯文本框的表单:
var postCfg = {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
transformRequest: function (data) {
return $.param(data);
}
};
$http.post(FormUrl,{num:num,size:size},postCfg).success(function(data){
console.log(data);
});