title: jQuery-File-Upload rails ajax
body: <p>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.</p>
  
  <p>my upload page's javascript:</p>
  
  <pre><code>&lt;html&gt;
  ..... html code ...
  
  &lt;%= javascript_include_tag 'js/vendor/jquery.ui.widget.js' %&gt;
  &lt;%= javascript_include_tag "js/jquery.iframe-transport" %&gt;
  &lt;%= javascript_include_tag "js/jquery.fileupload.js" %&gt;
  
  &lt;script&gt;
  $(function () {
      'use strict';
      var filestoupload = 0;
      $('#fileupload').fileupload({
          dataType: 'json',
           add: function(e, data) {
                  if(data.files[0]['size'] &gt; 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 &gt; 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');
  });
  &lt;/script&gt;
  </code></pre>