dqusbxh44823 2014-09-13 10:19
浏览 45
已采纳

从ajax运行php

i have a countdown timer when it finish it run a php script (file called ajax.php) the problem is the ajax.php run many times .

i want to get this result in the table

[id][content]
[1][timer]

but i get this result

[id][content]
[1][timer]
[2][timer]
[3][timer]
[4][timer]
[5][timer]
[6][timer]
[7][timer]
[8][timer]
[9][timer]
.....

this is the code

    <div id="counter"></div>

    <script src="jquery.js"></script>
    <script>
    var div = $('#counter');

    var n = 5000;

    var blured = false;

    var tid = setInterval(function() {
        if (blured) return;    
        n -= 100;
        div.text( (n / 1000).toFixed(1) + ' seconds passed' );
        if ( n <= 0 ) {


        div.text('Time passed!'); 
        $.ajax({

        url: 'ajax.php',
        type: 'post',
        success: function(data, status) {}

        });




        }


    }, 100);

    window.onblur = function() {
        blured = true;    
    };

    window.onfocus = function() {
        blured = false;    
    };


        document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\">&nbsp;</div>";
        // document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
        window.onblur = function() {
            blured = true;    
        };
        window.onfocus = function() {
            blured = false;    
        };


    </script>

and this is ajax.php

    mysql_connect("localhost","root","usbw") or die ("Couldn't connect to server");
    mysql_select_db("test") or die ("Coouldn't Select Database");


    $query = mysql_query("INSERT INTO add_delete_record VALUES ('', 'timer')");
  • 写回答

2条回答 默认 最新

  • doudong7256 2014-09-13 10:33
    关注
        var tid = setInterval(function() {
        if (blured) return;    
        n -= 100;
        div.text( (n / 1000).toFixed(1) + ' seconds passed' );
        if ( n <= 0 ) {
    
    
        div.text('Time passed!'); 
      clearTimeout(tid);
        $.ajax({
    
        url: 'ajax.php',
        type: 'post',
        success: function(data, status) {}
    
        });
    
    
    
    
        }
    
    
    }, 100);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型