The following form works well to upload a file and stays on the same page. So far so good, the file does make it to the server.
= form_tag("imgupload", remote: true, multipart: true, id: 'image_upload_form' ) do
.field
= label_tag :image
= file_field_tag :image
= submit_tag "Upload Image"
How can I get notified in Javascript when the file/form has finished uploading?
I tried the following but it doesn't fire any of the alerts:
$("#image_upload_form").bind("ajax:complete", function(evt, data, status, xhr) {
alert('Complete!');
});
$("#image_upload_form").bind("ajax:success", function(evt, data, status, xhr) {
alert('Success!');
});
$("#image_upload_form").bind("ajax:failure", function(evt, data, status, xhr) {
alert('Failure!');
});
try
$("#image_upload_form").ajaxComplete(function() {
alert('Complete!');
});
I couldn't get the JQuery bind to work. I found jQuery Form Plugin which does what I want though.
One solution could be to upload your image with jquery.
Here is a great screencast for that : http://railscasts.com/episodes/381-jquery-file-upload
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.