注 :
1 文件上传必须采用Content-Type:multipart/form-data; boundary=—-WebKitFormBoundarypHkhXOMllLo8SW36
2 angularjs默认的$http服务是content-type:application/json
附带ajax为application/x-www-form-urlencoded;charset=utf-8
问题:
1 需要自行修改配置$http的content-type头
2 文件+普通text一起会存在后端解析中文乱码问题(multipart/form-data导致)
解:
var date = new FormData();
var logFile = document.getElementById('logFile').files[0];
var backFile = document.getElementById('backFile').files[0];
date.append('file[0]', logFile);
date.append('file[1]', backFile);
var parmass = "?"
+ 'id=' + id + "&"
+ 'pageTitle=' + $scope.pageTitle + "&"
+ 'shopName=' + $scope.shopName + "&"
+ 'shopContact=' + $scope.shopContact + "&"
+ 'shopAddr=' + $scope.shopAddr + "&"
+ 'shopDesc=' + $scope.shopDesc + "&"
+ 'pageLogo=' + $scope.pageLogo + "&"
+ 'pageBackground=' + $scope.pageBackground;
$http({
method : 'POST',
url : "/portalmgr/portalPage/saveTemplate1" + parmass,
data : date,
headers : {
'Content-Type' : undefined
},
transformRequest : angular.identity
}).success(function(response) {
layer.alert('提交成功', {icon: 6});
});
![这里写图片描述](https://img-blog.csdn.net/20161228155757944?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDAzOTk3OQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
附录:
// 前端不做修改可以解决乱码问题
//String name1 = new String(request.getParameter(“pageTitle”).getBytes(“iso8859-1”), “utf-8”);
// 前端将参数放在路由后面可以解决中文乱码问题 如上面代码
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)