dpa0760 2015-01-24 11:58
浏览 68

如何在不使用php / ajax重新加载网页的情况下自动更新内容?

I'm trying to create an auction tool using PHP. The problem I'm having (and I appreciate its a basic one but I need clarification) is that I don't understand how to update the "auction price" automatically on each users screen without them having to take any action or without causing a full reload of the page.

So far I understand that Ajax is used to do this but if anyone could point me in the right direction or to any useful materials. My plan for my project so far is to use PHP and JavaScript so any solution would need to be compatible with these languages.

Note: I'm using a MySQL database.

  • 写回答

3条回答 默认 最新

  • dongyou9373 2015-01-24 12:13
    关注

    Php/Ajax example:

    In this example you have index.html and record_count.php files

    Here is the Code:

    index.html contains the html code and javascript call to load record_count.php

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
    <script type="text/javascript">
       var auto_refresh = setInterval(
          function ()
          {
             $('#load_tweets').load('record_count.php').fadeIn("slow");
          }, 10000); // refresh every 10000 milliseconds
    </script>
    
    <body>
         <div id="load_tweets"> </div>
    </body>
    

    and record_count.php has the php code

    <?php
    echo "some code or variable here";
    ?>
    

    you can change the javascript interval to suit your needs

    I'll leave you the blog link as a reference: 9lessons

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答