trying to call an external ajax function to exec the php script to update a table. it is somehow not working.. it is my first time programming in ajax, please point it out if there is anything obviously wrong. thanks.
<html>
<head>
<script>myAjaxFunctions.js</script>
</head>
<body>
<button type="button" onclick="clearT1();">Clear TableOne</button>
</body>
</html>
/**** This is "myAjaxFunction.js *****/
var asyncRequest;
function getContent(url)
{
try
{
asyncRequest = new XMLHttpRequest();
asyncRequest.onreadystatechange = stateChange;
asyncRequest.open('POST', url, true);
asyncRequest.send(null);
}
catch(exception)
{
alert('Request Failed.');
}
}
function clearT1()
{
//getContent("clearTable_exc.php");
try
{
asyncRequest = new XMLHttpRequest();
asyncRequest.onreadystatechange = stateChange;
asyncRequest.open('POST', "../clearTable_exc.php" , true); //// php page
asyncRequest.send(null);
}
catch(exception)
{
alert('Request Failed.');
}
}
function stateChange()
{
if(asyncRequest.readyState == 4 && asyncRequest.status == 200)
{
document.getElementById('contentArea').innerHTML = asyncRequest.responseText;
}
}
/*** this is the php page ****/
<?php
include('config.php');
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
$db = mysql_select_db(DB_DATABASE);
$query="update orders set order_status=1 where table_num=1";
mysql_query($query);
?>