问题描述
我正在尝试使用scriptData通过uploadify发送表单的其他数据,但是它不向后端PHP脚本发送任何内容.有人可以帮我吗?这是我正在尝试的..
I am trying to send form's additional data with uploadify using scriptData but it does not send anything to backend PHP script. Can someone help me with it please? Here is what I'm trying..
Javascript:
<script type="text/javascript">
$(document).ready(function() {
$("#fileUpload").fileUpload({
'uploader': 'uploadify/uploader.swf',
'cancelImg': 'uploadify/cancel.png',
'script': 'uploadify/upload.php',
'folder': 'files',
'multi': false,
'displayData': 'speed',
'scriptData' : {'name' : $('#name').val()},
onComplete: function (evt, queueID, fileObj, response, data) {
alert("Successfully uploaded: "+response);
}
});
});
</script>
HTML:
Name: <input name="name" id="name" /><br />
<div id="fileUpload">You have a problem with your javascript</div>
<a href="javascript:$('#fileUpload').fileUploadStart()">Start Upload</a> | <a href="javascript:$('#fileUpload').fileUploadClearQueue()">Clear Queue</a>
upload.php
(我尝试过POST和GET方法,均无效).
(I have tried both POST and GET methods, none works).
$name = $_GET['name'];
or
$name = $_POST['name'];
非常感谢您的帮助.
推荐答案
我知道这有点晚了,但是我试图自己解决这个问题,并尝试做与您相同的事情.
I know it's a little late, but I was trying to get this to work myself, and attempted to do the same thing you did.
您不能使用jQuery选择器在Uploadify的初始设置中获取名称"的值:
You can't use the jQuery selector to get the value of "Name" in the initial setup of Uploadify:
'scriptData' : {'name' : $('#name').val()}
这是一个计时问题.在评估jQuery选择器时,页面刚刚完成加载,并且您的名称"文本框(我假设)为空.上传时不会重新评估.
It's a timing issue. At the time the jQuery selector is evaluated, the page has just finished loading, and your 'Name' textbox (I assume) is empty. It does not get re-evaluated when the upload occurs.
但是,您可以随时更新脚本数据,包括在上传发生之前.
You can, however, update the scriptdata at anytime, including just before the upload occurs:
$('#myUpload').uploadifySettings('scriptData', {'Id':$('#IdTextBox').val() });
$('#myUpload').uploadifyUpload();
这样,您可以提取表单数据并将其与上载一起传递.这是最简单的示例,上传多个文件会变得更加复杂,但这足以使某人入门.
That way, you can extract form data and pass it along with the upload.This is the simplest example, it gets more complicated with multiple file uploads, but that should be enough to get someone started.
这篇关于Uploadify发送表单数据时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!