jquery - How to call javasscript_tag in rails? -
i followed each step of above question , here changes:
in show.html.erb (http://localhost:3000/posts/24) <% javascript_tag %> $(function() { setinterval(function(){ $.get("/posts/<%= @post.id %>"); }, 5000); }); <% end %> <span id="changed_data"> should change after every 5 seconds </span>
controller class
def show @post = post.find(params[:id]) respond_to |format| format.js format.html end
end
added new file
app/views/posts/show.js.erb $("#changed_data").html("<h2> changed </h2>");
but sounds javascript_tag
not calling jquery
method. doing wrong here?
try this:
<% javascript_tag %> $(function() { setinterval(function(){ $.get("/posts/<%= @post.id %>"); }, 5000); }); <% end %>
change
<script> $(function() { setinterval(function(){ $.get("/posts/<%= @post.id %>"); }, 5000); }); </script>
it should work.
Comments
Post a Comment