I'm using the jQuery fileupload plugin.
I've placed the uploader inside a form (which may not be ideal). The files are uploaded automaticly when added to the queue.
This is the part that handles that:
// This function is called when a file is added to the queue;
// either via the browse button, or via drag/drop:
add: function (e, data) {
var tpl = $('<li class="working"><input type="text" value="0" data-readOnly="1" /><p></p><i class="icon-remove"></i></li>');
// Append the file name and file size
tpl.find('p').text(data.files[0].name)
.append('<span>' + formatFileSize(data.files[0].size) + '</span>');
// Add the HTML to the UL element
$t.find('.auc-upload-list').append(tpl);
data.context = tpl;
// Initialize the knob plugin
tpl.find('input').knob({
width: 20,
height: 20
});
// Listen for clicks on the cancel icon
tpl.find('i').click(function(){
if(tpl.hasClass('working')){
jqXHR.abort();
}
tpl.fadeOut(function(){
tpl.remove();
});
});
// Automatically upload the file once it is added to the queue
var jqXHR = data.submit();
},
var jqXHR = data.submit(); initiates the posting.
Unfortunately, all the other form fields are posted aswell. Can I prevent that somehow? So that the fileupload plugin only posts the given file input field?
Or maybe that I tell the plugin which field it can and cannot post?