最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adding dynamic fields to Uploadify - Stack Overflow

programmeradmin1浏览0评论

I am just trying to add a simple text field for a title and have it posted to uploadify.php, but it's not working.

Javascript:

$(function() {
    $("#file_upload").uploadify({
        'formData'      : {"title": $("#title").val()},
        'swf'           : '/uploadify/uploadify.swf',
        'uploader'      : '/uploadify/uploadify.php',
        'onUploadStart' : function(file) {
                $("#file_upload").uploadify("settings", "title");
        }
    });
});

HTML:

<input type="text" id="title" name="title" />
<input type="file" name="file_upload" id="file_upload" />

If I replace {"title": $("#title").val()} with {"title": "title"} it works fine but then it's not dynamic, it's just set to title. How can I get it passing the actual text field data? I've tried several things myself, but the Uploadify documentation is pretty thin.

I am just trying to add a simple text field for a title and have it posted to uploadify.php, but it's not working.

Javascript:

$(function() {
    $("#file_upload").uploadify({
        'formData'      : {"title": $("#title").val()},
        'swf'           : '/uploadify/uploadify.swf',
        'uploader'      : '/uploadify/uploadify.php',
        'onUploadStart' : function(file) {
                $("#file_upload").uploadify("settings", "title");
        }
    });
});

HTML:

<input type="text" id="title" name="title" />
<input type="file" name="file_upload" id="file_upload" />

If I replace {"title": $("#title").val()} with {"title": "title"} it works fine but then it's not dynamic, it's just set to title. How can I get it passing the actual text field data? I've tried several things myself, but the Uploadify documentation is pretty thin.

Share Improve this question edited Jul 9, 2012 at 16:26 asked Jul 9, 2012 at 15:40 user1461465user1461465
Add a ment  | 

1 Answer 1

Reset to default 8

The Uploadify documentation found here says otherwise, but this seems to be the correct way to utilize dynamic fields with Uploadify. In any case, it works.

$("#file_upload").uploadify({
        'swf'           : '/uploadify/uploadify.swf',
        'uploader'      : '/uploadify/uploadify.php',
        'onUploadStart' : function(file) {
                $("#file_upload").uploadify("settings", 'formData', {'title' : $("#title").val()});
        }
    });
});

Edit: It isn't required to have the formData declared in the first $("#file_upload").uploadify() so I removed it. Include it there as well if you want to use it to set default values.

发布评论

评论列表(0)

  1. 暂无评论