1

I would like to be able to add a mysql query to my Javascript function so that every time the counter restarts then it will add 1 or a certain number of an item into the mysql database. Could you help me with this?

<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>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mason
  • 81
  • 2
  • 8
  • I am afraid you can not do it with js only. That's why and how to - http://stackoverflow.com/questions/3020751/can-javascript-connect-with-mysql – Mr. L Feb 22 '11 at 16:33

1 Answers1

1

Javascript cannot talk to MySQL directly. You can, however, set up an AJAX service as an intermediary - have Javascript talk to this service, the service talks to MySQL, and then returns the query results.

You can roll your own AJAX handlers in Javascript, but it's far easier to use a premade one, such as provided by jQuery. The server-side handler would be (typically) written in something like PHP, Perl, Ruby, etc...

Marc B
  • 356,200
  • 43
  • 426
  • 500