Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8683161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:58:04+00:00 2026-06-12T21:58:04+00:00

I am trying to display the progress percentage when i upload a file and

  • 0

I am trying to display the progress percentage when i upload a file and unzip it. I am using ruby-zip to unzip the file. While unzipping I increment the counter and store it in database. I have a form like

<% form_tag '/unzip', :multipart => true do %>
  <%= file_field_tag "zipfile", :size => 12 %> 
  <button class="add_button" type="submit" value="Add"> Add </button>
<% end %>
<div class="progress">
</div>

In unzip action there is everything that does unzipping and storing the value in database. Now, I would like to update the .progress div every 2 seconds or so. First, I tried to make ajax call when the button is clicked and call another method that gets this progress. But I was not successful because, this simple code below was giving me error.

<script>
$(".add_button").click(function() {
  $.ajax({
    url: "/get_progress", 
    method: "POST"
  })
})
</script>

In get_progress method, I just take out the value from the database like

def get_progress
  @progress = Progress.last.value
  respond_to do |format|
    format.js
  end
end

For simple checking purpose, I just do console.log("rendered") in the get_progress.js.erb. But this never gets called as there is error message before it. But, I checked and the ajax call is making request to get_progress.

But the problem is, I am getting error in xhr.send((s.hasContent && s.data) || null) in jquery1.6.3 line number 7948. I think I am getting this error because this page is redirected somewhere else during the ajax call and there is another request going on while I make the call as it is obvious that I have another action called when the form gets submitted.

When I print out the error on ajax call by doing:

error:function(xmlHTTPRequest, textStatus, errorThrown){
  console.log(xmlHTTPRequest);
}

I am getting this:

Object {readyState = 0 ,status = 0 ,statusText = "error" }

I think my problem is similar to this question. But, the answer presented here did not solve my issue.

Is there any way I can solve this issue? I hope the question is clear!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:58:05+00:00Added an answer on June 12, 2026 at 9:58 pm

    This seems to work for me when I changed the ajax call from a post to a get.

    View:

    Progress:
    <div id="progress">
    </div>
    
    <br />
    
    <button class="add_button" type="submit" value="Add"> Add </button>
    <script>
    $(".add_button").click(function() {
      $.ajax({
        url: "/get_progress", 
        method: "get",
        dataType: "script"
      })
    })
    </script>
    

    Controller:

    def get_progress
      @progress = Progress.last.value
      respond_to do |format|
        format.js
      end
    end
    

    get_progress.js.erb:

    $("#progress").text("<%= @progress.to_s %>");
    

    Some obvious things to check:

    • You have added the correct route for “/get_progress” with a “get” action
    • JQuery is installed and working
    • That the code in get_progress.js.erb is correct. If the JS and the embedded rails logic are not working properly, often it looks like “nothing is happening”. Start with something simple like the above…

    P.S. To run it in loop:

    function updateProgress() {
          $.ajax({
            url: "/get_progress", 
            method: "get",
            dataType: "script"
          });
    }
    
    // Set the function above to run every 2 seconds
    var i = setInterval(updateProgress, 2000);
    

    And update get_progress.js.erb:

    $("#progress").text("<%= @progress.to_s %>");
    var checkprogress = <%= @progress.to_i %>;
    if (checkprogress == 100) {
       // Stop the function running. Should add clearInterval to error handling of ajax also
       clearInterval(i);
    }
    

    Edit

    If there is some kind of conflict between the submit of the unzip action and retrieving the progress, I would recommend that you make the unzip submit asynchronous, using remotipart. Then change the form for unzip to:

    <% form_tag '/unzip', :html => { :multipart => true }, :remote => true do %>
    

    and add a create.js.erb file with <%= remotipart_response do %> as per the remotipart readme. I would still recommend that the get_progress ajax call is a get method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display the progress bar(marque) in a separate form (progressForm) while
I'm trying to get a Gtk::Spinner object to display while calculations are in progress
I'm trying to find a way to display a progress bar with a percentage
Hello I've been trying to display progress using the annular determinate for the last
I am trying to perform a low-level file copy but also display my progress
I'm trying to create a simple display of progress for the user while actions
I am trying to display a progress bar using threading .. I accept that
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
I am trying to display a progress dialog during downloading of data. Right now,
I'm not sure if this is possible. I'm trying to display a progress bar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.