使用js调用php,js在get请求时停止,两个文件都单独工作

时间:2014-06-25 14:53:50

标签: javascript php ajax

对不起我的措辞不好,我是网络技术的新手。我花了几个小时试图弄清楚如何解决这个问题并且没有在哪里,当页面加载do_something_with_sql.php没有运行时没有任何反应,并且计数器没有增加,但两个文件分别工作正常

<?php
echo "<p>Theoretical number of queries <div id =\"queries\">0</div></p>";
?>
<script type="text/javascript">
queries = 0;
count = 0;

function test()
{
    $.get("do_something_with_sql.php?count=" + count);

    count = count + 40;
    queries++;
    document.getElementById("queries").innerHTML = queries;
}

setInterval(test, 1000);


</script>

编辑:这是对代码的最新更新,但它什么也没做,没有控制台错误,我也在同一个文件夹中有JQuery文件。

<?php
echo "<p>Theoretical number of queries <div id =\"queries\">0</div></p>";
?>
<script type="text/javascript" src="jquery-2.1.1.js">
    queries = 0;
    count = 0;

    function test()
    {
        $.get('does_something.php?count=' + count, function()
        {
            count = count + 40;
            queries++;
            document.getElementById('queries').innerHTML = queries;
            setTimeout(test, 1000);
        });

    }

    setTimeout(test, 1000);

</script>

编辑编辑: 下面是固定版和工作版。

<?php
echo "<p>Theoretical number of queries <div id =\"queries\">0</div></p>";
?>
<script type="text/javascript" src="jquery-2.1.1.js"></script>
<script type="text/javascript">
    queries = 0;
    count = 0;

    function test()
    {
        $.get('does_something.php?count=' + count, function()
        {
            count = count + 40;
            queries++;
            document.getElementById('queries').innerHTML = queries;
            setTimeout(test, 1000);
        });

    }

    setTimeout(test, 1000);

</script>

1 个答案:

答案 0 :(得分:2)

我没有专家,只有一件事是肯定的,行:

$.get("do_something_with_sql.php?=" + count);

应该是:

$.get("do_something_with_sql.php?count=" + count);