jquery - 如何将变量添加到加载的文件
问题描述
我有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();
}
});
});
谢谢你,等待回复。
解决方案
您还需要在表单中附加您的 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);
}
});
});
推荐阅读
- c# - PlatformChecks.RequestPermissions 不可用
- python - 音乐播放器应用
- python-3.x - pathlib 使用双斜杠返回非 Windows 路径
- javascript - onclick 不更新。即使在使用 .onclick="hideList()" 之后也显示旧值;
- javascript - 如何使用Javascript在数组中查找json对象的索引
- mysql - 如何从主机 Windows 连接到 WSL mysql
- r - 在列范围内矢量化名称替换
- java - 将映射值分配给输入字符串
- jquery - 单击当前选项卡后不显示弹出
- python - flask+uwsgi+nginx+centos 导入模块numpy报错