Few months ago I wrote a jQuery plugin for AJAX file uploading. It’s based on the idea used by WebToolkit Ajax file upload.
The code is here.
How to use it?
$(document).ready(function() {
$('#your_form_id').uploadForm('your_upload_script', {
'onStart': function() {
alert('Uploading...');
return true;
},
'onComplete': function(data) {
alert('Complete: '+data);
},
'onError': function(cause) {
alert('Error: '+cause);
},
'timeout': 5000
});
});
How does it work?
- Page loads, and the form’s submit event is hooked;
- User selects a file, and clicks in the submit button;
- The hook function is triggered by the submit event, creates an iframe, and appends it to the document root;
- The onStart callback is called;
- The form’s target property is set to the iframe element, avoiding the full page reload.
- The submit event is executed normally;
- The onComplete callback is called after the iframe reload;
