使用uploadify发送其他字段数据

时间:2011-02-18 16:37:12

标签: php javascript jquery uploadify

我想用uploadify发送一个额外的字段,我无法使用以下代码获取后端php文件的字段值。有人可以看看我的HTML和js代码是否正确? 感谢

<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':'', 'location':''},
        'onSelectOnce' : function(event,data) {
            $("#fileUpload").uploadifySettings('scriptData', {'name' : $('#name').val()});
        }
    });
});
</script>

HTML:

<h2>Single File Upload</h2>
        <p>Display speed</p>
         Name: <input name="name" id="name" type="text" maxlength="255" size="50" />
        <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的

$name = $_GET['name'];

1 个答案:

答案 0 :(得分:0)

试试这个

'scriptData': {'name':$("#name").val()},
<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':$("#name").val(), 'location':''},
    'onSelectOnce' : function(event,data) {
        $("#fileUpload").uploadifySettings('scriptData', {'name' : $('#name').val()});
    }
});

});