gpt4 book ai didi

jquery - 上传表单数据: Why jquery won't send parameters via post?

转载 作者:行者123 更新时间:2023-12-01 00:57:42 24 4
gpt4 key购买 nike

这是我的代码:

$('#file_upload').uploadify({
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php',
'onSelect' : function(file) {
$('#start').removeClass('hidden');
},
'method' : 'post',
'formData' : {
'to': $('input#to').val(),
'from': $('input#from').val(),
'subject': $('input#subject').val()
},
'onQueueComplete' : function(queueData) {
window.location.replace("index.php?success=uploaded");
},
'onUploadSuccess' : function(file, data, response) {
alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
}
// Your options here
});

如您所见,我通过 POST 方法发送三个参数 TO、FROM、SUBJECT。

有服务器脚本

if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);

if (move_uploaded_file($tempFile, $targetFile)) {

echo $_REQUEST['subject'];
} else {
echo "Something wrong";
}
}

并回显 $_REQUEST['subject'];什么也不返回我的错误在哪里?

如果我将 'subject': $('input#subject').val() 更改为 'subject': 'test subject' ,它就可以工作。但我需要从输入发送一个值。我该怎么做?

非常感谢

最佳答案

您在首次实例化 Uploadify 时设置 formData,而不是在提交上传时设置。如果您这样做,您将在加载页面时将 formData 设置为这些字段的值。

相反,使用 onUploadStart 选项在文件上传之前设置 formData...

$('#file_upload').uploadify({
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php',
'onSelect' : function(file) {
$('#start').removeClass('hidden');
},
'method' : 'post',
'onQueueComplete' : function(queueData) {
window.location.replace("index.php?success=uploaded");
},
'onUploadStart' : function(file) {
$('#file_upload').uploadify('settings','formData',{
'to': $('input#to').val(),
'from': $('input#from').val(),
'subject': $('input#subject').val()
});
}
'onUploadSuccess' : function(file, data, response) {
alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
}
// Your options here
});

关于jquery - 上传表单数据: Why jquery won't send parameters via post?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11276307/

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