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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -