I am using Turbolinks in my rails project . When I clicked upload button(ajax call),it fails and the error section is showing Uncaught TypeError: Cannot read property 'length' of undefined. The same problem is showing with regular link(no ajax) which is caused by turbolinks I think because turbolinks uses ajax in the background.
my upload page's javascript:
<html>
..... html code ...
<%= javascript_include_tag 'js/vendor/jquery.ui.widget.js' %>
<%= javascript_include_tag "js/jquery.iframe-transport" %>
<%= javascript_include_tag "js/jquery.fileupload.js" %>
<script>
$(function () {
'use strict';
var filestoupload = 0;
$('#fileupload').fileupload({
dataType: 'json',
add: function(e, data) {
if(data.files[0]['size'] > 20000000) {
$('#errors_append').html('maximum size for file allowed is 20 mb');
} else {
data.submit();
}
},
done: function (e, data) {
$.each(data.result.files, function (index, file) {
filestoupload++;
$('').text(file.name + ' ' + 'uploaded successfully').appendTo('#files_append');
if (filestoupload > 2) {
$('#file_button').attr("disabled","disabled");
}
});
$("#btn_text").html('Add more files');
},
start: function (e, data) {
$('#progress .progress-bar').css(
'width',
0 + '%'
);
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css(
'width',
progress + '%'
);
},
success: function(xhr){
$('#progress .progress-bar').attr('class', 'progress-bar progress-bar-success');
$('#errors_append').empty();
},
error: function(xhr){
var errors = $.parseJSON(xhr.responseText).error
$('#errors_append').html(errors);
$('#progress .progress-bar').attr('class', 'progress-bar progress-bar-danger');
}
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
});
</script>

js/jquery.fileupload.jsfile in your directory? and why are you using js in your view?