I am trying to implement jquery replacement for the old periodically_call_remote. I got the following code from another stackoverflow thread here:
$(document).ready(
function(){
setInterval(function(){
$('#mydiv').load('/controller/action');
}, 3000);
});
But I am struggling to make it work. If I understand UJS correctly, if I do the following things:
- Place the script in application.js
- include application.js in my layout (which javascript_include_tag :defaults does)
- have a DOM element in my view template with id='mydiv'
Then the function should automatically bind to 'mydiv' and execute after the page is loaded, right? Is there a step I am missing? I should not have to name the function or call it directly in the view, correct?
Second, how can I dynamically update the load URL. For instance, I have a nested resource with the path '/controller/:id/action' ... how do I dynamically insert the :id value into the load path at render time?