首页 > 解决方案 > 如何将变量添加到加载的文件

问题描述

我有id_p应该与服务器上上传的文件一起发送的变量。

有四个这样的文件要加载,每个文件都必须从变量中加载此信息

$(function () {

var id_p = document.getElementById('primarie').value();
console.log(id_p);

$('#dxfUpload').fileupload({
    url: 'upload-manager.php',
    start: function (e, data) {
        document.getElementById('loading').style.display = "block";
    },
    done: function (e, data) {
        document.getElementById('loading').style.display = "none";
    }
});


$('#csvUploadGA').fileupload({
    url: 'upload-manager-csv.php',
    start: function (e, data) {
        document.getElementById('loading').style.display = "block";
    },
    done: function (e, data) {
        document.getElementById('loading').style.display = "none";
    }
});

$('#csvUploadB').fileupload({
    url: 'upload-manager-B.php',
    start: function (e, data) {
        document.getElementById('loading').style.display = "block";
    },
    done: function (e, data) {
        document.getElementById('loading').style.display = "none";
        addLayer();
    }
});
});

谢谢你,等待回复。

标签: jqueryhtmlforms

解决方案


您还需要在表单中附加您的 id_p:

$('#img-upload').change(function(e){
 var id = $("input[name=id]").val();
 var file = this.files[0];
 var form = new FormData();
 form.append('img-upload', file);
 form.append('uploaded-id', id); //Here is the appended id_p 
  $.ajax({
    url : 'upload.php',
    type : 'POST',
    cache : false,
    contentType : false,
    processData : false,
    data : form,
    success : function(response) {
         $("#responsePanel").css({'display':'block'}).hide().html(response.html).fadeIn(1000);
    }
 });
});

推荐阅读