jQuery技术:在rails 3.1中每10秒重新加载一页

我有一个rails 3.1rc4应用程序,我想在每10秒后更新我的index.html.erb文件中的div。 如果可以通过jquery完成,我不会这样做吗? 有一个更新方法,但我不,如果它只是原型。 任何样本都会很棒

    将您的问题分解为子任务,这是您必须处理的问题:

    对于1,请查看jquery的.get

    Description: Load data from the server using a HTTP GET request.

    2,查看jquery的.html

     Get the HTML contents ... or set the HTML contents of every matched element. 

    对于3,请查看setInterval

     Summary Calls a function or executes a code snippet repeatedly, with a fixed time delay between each call to that function. Returns an intervalID. 

    最终解决方案

    HTML代码:

     

    Javascript代码

      function update() { $.get('/', function(data) { $('#divToChange').html(data); }); } $(document).ready(function($){ window.setInterval('update()', 10*1000); }); 

    我假设你熟悉javascript和AJAX(如果你需要的话)。

    这段javascript使用本机setInterval函数,该函数每10秒调用一次updateDiv函数。

     var timer = setInterval(updateDiv, 10000); function updateDiv() { // do update } 

    编辑:没有jQuery的完整示例;

          

      以上就是jQuery教程分享在rails 3.1中每10秒重新加载一页相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/532311.html

      (0)
      上一篇 2020年12月21日
      下一篇 2020年12月21日

      精彩推荐