javascript - How to refresh a div without reloading the entire page? -


i have div , want refresh content without reloading entire page.

i tried many times many methods (ajax call, javascript, etc...), don't have did it.

my div displays entire content of modelname.all , in particular div, can add new entities (thanks form) of model use.

i display div rails partial view.

currently, use when user submit form :

$('#articlesdiv').html("<%= escape_javascript (render partial: 'articles') %>"); 

but seems partial view doesn't have up-to-date model. because before add new entity, see example 5 elements, , after add new entity, see again 5 elements. test purposes, use javascript alert displays modelname.all.count

and alert displays 5 ! when @ database content (before alert), can see 6 elements ! , when refresh page manually, div displays 6 elements.

code explain :

the main view :

<div id="articlesdiv">   <%= render(:partial => "articles") %> </div> 

_articles (the partial view) :

<script>   alert('<%=article.all.count%>'); </script>  <% article.all.each |article|) %>  <strong><%= article.name %></strong><br />  <% end %> 

my goal have smooth interface doesn't reload entire page times add other article.

you can have contents of div in partial , load content using url say, /divcontents. can refresh <div> using .load():

$('#articlesdiv').load("/divcontents"); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -