我正在使用ajax提交包含数组,文本字段和文件的多部分表单.
我将每个VAR附加到主数据上
var attachments = document.getElementById('files');
var data= new FormData();
for (i=0; i< attachments.files.length; i++){
data.append('file', attachments.files[i]);
console.log(attachments.files[i]);
data.append ('headline', headline);
data.append ('article', article);
data.append ('arr', arr);
data.append ('tag', tag);
Run Code Online (Sandbox Code Playgroud)
然后我使用ajax函数将其发送到PHP文件以存储在sql DB中.
$.ajax({
type: "post",
url: 'php/submittionform.php',
cache: false,
processData: false,
contentType: false,
data: data,
success: function(request) {$('#box').html(request); }
})
Run Code Online (Sandbox Code Playgroud)
但在PHP方面,arr变量(即数组)显示为字符串.
当我不使用ajax作为表单数据发送它但使用简单$.POST选项时我会在PHP端将其作为数组获取,但是我也无法发送文件.
任何解决方案