I have a partial to load when a search is detected. It may take a very long time to load in some cases, so I would like it to load via Ajax once the page is fully loaded otherwise it will most likely cause a timeout.
The way I am doing it currently is resulting in a synchronously load.
I would also like a loading screen to be shown, until it's fully loaded. This is working currently but only with the timeout set, as its a synchronous load.
<% if(params[:q][:name_cont].present?) %>
<script>
$( document ).ready(function() {
function load_partial() {
$("div.super_search").replaceWith('<%= escape_javascript(render partial: 'super_search_tp') %>');
}
// use setTimeout() to execute
setTimeout(load_partial, 1000)
});
</script>
<div class="super_search">
<i class='fa fa-spinner fa-spin'></i> Loading Product Analysis...
</div>
<% end %>