2

I have a view in my rails app: blah.app/units/status

This displays a status of all my units. I'd like to have the page automatically refresh via javascript but I'm not sure how to do it.

I tried writing this but it doesn't reload:

<script>
  $(function() {
    setInterval(function(){
      $.getScript("/units/status");
    }, 10000);
  });
</script>

Can someone point out where I'm going wrong here?

1
  • I also tried this which works, but not sure if it's the best way to do it. '<script language="javascript" type="text/javascript">setTimeout("location.reload();",10000);</script>' Commented Mar 20, 2013 at 14:53

1 Answer 1

1
$(document).ready(function() {
  setTimeout(function() {
    window.location.reload();
  }, 10000);
});
Sign up to request clarification or add additional context in comments.

3 Comments

jQuery isn't tagged, and there's no reason to wait until the DOM is ready anyways
I don't see your witty solution to teknull problem, just complaining about the given solutions... that work.
I don't understand what you mean. For some reason, I was focusing on teknull's comment to his question, that already tried basically what you have. So I don't know how I missed that they are already using jQuery - that's my fault. But I don't see where I was complaining though. It would probably help if you explained some or proved that your almighty code worked, instead of just posting code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.