[英]AJAX post multiple data after file upload
我有這段代碼使用$_FILES
上傳文件:
$('input[type=file]').change(function() {
var FilesID = $(this).attr('id');
alert(FilesID);
var data = new FormData();
jQuery.each(jQuery("#" + FilesID)[0].files, function(i, file) {
data.append('file-'+i, file);
});
jQuery.ajax({
url: 'upload/index.php',
data: data + '&picid=' + FilesID,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(data){
$("#alertspan").text(data);
document.getElementById("alertbox").style.display = 'block';
setTimeout(function() {document.getElementById("alertbox").style.display = 'none';},5000);
}
});
});
我想在文件上傳的頂部添加POST數據,基本上是這樣,除了上傳的文件之外,您的picid
等於變量FileID
。
怎么樣使用data.append('picid', FilesID);
在調用jQuery.ajax()
?
如果您可以使用GET而不是POST,則只需使用'upload/index.php?picid=' + encodeURIComponent(FilesID)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.