Uploading Files in the Background - J Query

File upload is part of many web applications but badly supported by browsers. The biggest problem is the lack of feedback of the upload status, while any action of the users disrupts the upload. A simple progress bar could improve the feedback but requires quite some work on the server side, while the problem of disruptive actions remains.


To improve the situation, file uploads should be performed in the background. This allows the application to continue accepting other user input.
The jQuery form plugin makes it trivial to switch from the native browser upload to Ajax background uploading. With this form:

all you need to add is a call to ajaxForm:

However, just doing the upload in the background without any feedback of the completed upload isn’t enough, so we use the success option to display an alert about the successful upload:


The ajax Form method binds itself to the submit event of the form, which allows it to also include the button used to submit the form in the Ajax request. The latter isn’t available when using ajax Submit. The ajax Submit method is useful on its own when the form submit is handled elsewhere, for example, by the validation plugin. To integrate validation and Ajax submit,ajax Submit should be used in the submit Handler option:

In addition to the alert, the clear Form method, also provided by the form plugin, removes all values from the form. This makes it easy for the user to upload another file.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

J Query Topics