gpt4 book ai didi

javascript - 追加后FormData为空

转载 作者:行者123 更新时间:2023-12-01 15:04:25 27 4
gpt4 key购买 nike

我正在使用 Ionic 的每个人我都尝试将文件发送到我的服务器,但是当我在控制台检查时,表单数据在追加后仍然为空,我认为我发现它是空的并且没有数据插入到我的数据库中。

PS:我使用许多输入文件。

这是 Controller :

.controller('perProfil', function($scope, annonceService, TDCardDelegate, $timeout, $http, $rootScope) {
$scope.data = {}

$scope.uploadedCin = function(element) {
$scope.$apply(function($scope) {
var files = element.files;
$rootScope.cin = files[0];
})
}

$scope.uploadedbultin = function(element) {
$scope.$apply(function($scope) {
var files = element.files;
$rootScope.bult = files[0];
$rootScope.FormData.append("bult", files[0]);
})
}

$scope.uploadedavis = function(element) {
$scope.$apply(function($scope) {
var files = element.files;
$rootScope.avis = files[0];
})
}

$scope.uploadedCertif = function(element) {
$scope.$apply(function($scope) {
var files = element.files;
$rootScope.certif = files[0];
console.log($rootScope.certif);
})
}

$scope.uploadedFile = function(element) {
var url = 'http://localhost/documents?token=' + localStorage.getItem("token");

console.log($rootScope.FormData);
var fd = new FormData(this);

fd.append("file", JSON.stringify($rootScope.cin));
fd.append("butin", $rootScope.bult);
fd.append("avis", $rootScope.avis);
/fd.append("certifScol",$rootScope.certif);

var data = {
"idUser": "name",
"type": "type"
}

fd.append("data", JSON.stringify(data));
console.log(fd);

$http.post(url, fd, {
headers: {
'Content-Type': 'multipart/form-data'
},
transformRequest: angular.identity
})
.success(function(data) {
console.log(data);
})
.error(function(data) {
console.log(data);
})
}
})

最佳答案

根据 the answer here: ...
var formData = new FormData(form);
for (var [key, value] of formData.entries()) {
console.log(key, value);}
//or console.log(...formData)

关于javascript - 追加后FormData为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39797392/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com