Dynamic scriptData in jQuery Uploadify
I'm pretty new to javascript and jQuery. I'm using Uploadify to upload images to the server. There are multiple Uploader objects on the page. I need to pass the id of the U开发者_如何学编程ploader object being used to the server. This is what I have so far:
$('input.ImageUpload').uploadify({
...
'scriptData': {'id': ??????},
...
});
How can I make this happen? I've tried "this.id" and "$(this).attr('id')". Am I even going about this in the correct way?
I'm not sure if this is ideal, but this is what I ended up doing:
$('input.ImageUpload').each(function() {
$(this).uploadify({
...
scriptData({'id': $(this).attr('id')},
...
});
});
This is how I use it successfully:
$(document).ready(function() {
$(".upload").each(function() {
$(this).uploadify({
'uploader' : '/code/js/jquery.uploadify/example/scripts/uploadify.swf',
'script' : '/code/js/jquery.uploadify/example/scripts/uploadify.php',
'cancelImg' : '/code/js/jquery.uploadify/example/cancel.png',
'folder' : '<?=$upload_path?>' + $(this).attr('id'),
'queueID' : 'fileQueue',
'auto' : true,
'multi' : false,
'scriptData' : ({'var_name': 'this_var_value'}),
'fileDesc' : 'Images and PDF files only! (JPG, PNG, PDF)',
'fileExt' : '*.pdf;*.jpg;*.jpeg;*.png',
'buttonText' : 'browse' + $(this).attr('id')
});
});
});
<div id="fileQueue"></div>
<input class="upload" type="file" name="ImageUpload" id="_ID_1" /><br />
<input class="upload" type="file" name="ImageUpload" id="_ID_2" /><br />
<input class="upload" type="file" name="ImageUpload" id="_ID_3" /><br />
精彩评论