javascriptmysqlajaxtimertask

Not sure how to do ajax functions inside of Javascript to get to mysql


I'm not quite sure how to go about putting an ajax function inside of my Javascript timer so that every time it restarts then it'll add one of the item into the database. I've been looking and I found this: http://www.tizag.com/ajaxTutorial/ajax-mysql-database.php but I'm not quite sure how to implement it into the code, so if you could help me it'd be appreciated.

Here's my code so far:

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

function timedCount() {
document.getElementById('txt').value = c;
c = c - 1;
if (c <= -1) {
mineCount++;
var _message = "You have mined " + mineCount + " iron ore" + (((mineCount > 1) ? "s" : "") + "!");
document.getElementById('message').innerHTML = _message;
startover();
}
}

function startover() {
 c = 10;
clearTimeout(t);
timer_is_on=0;
doMining();
}
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>
<html>
<center>
<div id='message'></div>

Solution

  • try including jquery and put $.post('path/to/file.php', {param1: value1}); in your doMining() function