Reputation: 189
I'm doing a RoR page and after a form the next page takes a lot to load, so i wish to have a loading page between the submit and the next page
<%= form_tag(next_path, :id => 'myform') do %>
<%= label_tag "My data" %>
<%= text_field "name", "", placeholder: "Your name" %>
<%= submit_tag 'Next' %>
<% end %>
Submit
Loading... //Here display the loading screen
A lot time after displays the next page
"Hello to the next page User"
EDIT
The loading screen should be in the start page, because the next page does a lot of sql queries and doesn't take javascript functions until it finishes
Solutions from rails to jquery are welcome
Upvotes: 1
Views: 5755
Reputation: 4296
This is pretty easy. Add a hidden "loading" message to your layout (or just the forms that submit to slow loading pages)
<div id="slow_warning" style="display:none">
Loading...
</div>
define a JavaScript function that shows the loading message
function show_slow_warning() {
$("#slow_warning").show();
}
then call that function whenever you trigger navigation to a slow page. You can do this with an onclick
handler for links or onsubmit
handler for forms. If you want to be really tricky (and clean) you can assign the handlers unobtrusively.
$(document).ready(function() {
$('a.link_to_slow_page').click(function(){
show_slow_warning();
});
});
Upvotes: 1