gpt4 book ai didi

javascript - jQuery Ajax 上传和 ID

转载 作者:行者123 更新时间:2023-12-03 05:15:32 26 4
gpt4 key购买 nike

你好,我得到了这个代码:

$(document).ready(function(){

$('#upload-file-selector').change(function(){

var $currID = $("#upload-file-selector").attr('data-uid')

$(this).simpleUpload("uploadFile.php", {

start: function(file){
//upload started
$('#filenameD').html(file.name);
$('#progressD').html("");
$('#progressBarD').width(0);
},

progress: function(progress){
//received progress
$('#progressD').html("Progress: " + Math.round(progress) + "%");
$('#progressBarD').width(progress + "%");
},

success: function(data){
//upload successful
$('#progressD').html("Success!<br>Data: " + JSON.stringify(data));
},

error: function(error){
//upload failed
$('#progressD').html("Failure!<br>" + error.name + ": " + error.message);
}

});

});

});

它适用于这个插件: SimpleUpload

如你所见,我有 var currID。如何将此 ID 与文件一起发送到 PHP?如何将 var 绑定(bind)到 JSON 字符串?

最佳答案

如果您想通过 POST 传递 $currID,请使用 SimpleUpload 的 data 选项。

http://simpleupload.michaelcbrook.com/#settings

data object - A set of key-value pairs containing the POST data you would like to send to the server along with each file. This is not automatically populated by any surrounding forms.

使用您的代码:

$(document).ready(function(){
$('#upload-file-selector').change(function(){;
var $currID = $("#upload-file-selector").attr('data-uid')
$(this).simpleUpload("uploadFile.php", {
data: {
"id": $currID
},
start: function(file){
//upload started
$('#filenameD').html(file.name);
$('#progressD').html("");
$('#progressBarD').width(0);
},
progress: function(progress){
//received progress
$('#progressD').html("Progress: " + Math.round(progress) + "%");
$('#progressBarD').width(progress + "%");
},
success: function(data){
//upload successful
$('#progressD').html("Success!<br>Data: " + JSON.stringify(data));
},
error: function(error){
//upload failed
$('#progressD').html("Failure!<br>" + error.name + ": " + error.message);
}
});
});
});

关于javascript - jQuery Ajax 上传和 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41622552/

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