1

我希望能够在我的 Javascript 函数中添加一个 mysql 查询,这样每次计数器重新启动时,它都会在 mysql 数据库中添加 1 个或一定数量的项目。你能帮我解决这个问题吗?

<head>
<script type="text/javascript">
var c=10;
var t;
var timer_is_on=0;

function timedCount() {
    document.getElementById('txt').value = c;
    c = c - 1;
    if (c == 0)
        c = 10;
}

function doMining() {
    if (!timer_is_on) {
        timer_is_on = true;
        t = setInterval(function () {
            timedCount();
        }, 1000);                
    }
}

</script> 

<SPAN STYLE="float:left">
<form>
<input type="button" value="Mining" onClick="doMining()">
<input type="text" id="txt">
</form>
</SPAN>
4

1 回答 1

1

Javascript 不能直接与 MySQL 对话。但是,您可以将 AJAX 服务设置为中介 - 让 Javascript 与该服务对话,该服务与 MySQL 对话,然后返回查询结果。

您可以在 Javascript 中使用自己的 AJAX 处理程序,但使用预制的处理程序要容易得多,例如jQuery提供的。服务器端处理程序将(通常)用 PHP、Perl、Ruby 等编写...

于 2011-02-22T16:34:15.487 回答