I have included some simple AJAX into my site (
http://www.ajaxcounter.com for source).
Here is the source:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Ajax Counter - Get a Free Hit Counter for your Website!</title>
<script language="javascript" type="text/javascript">
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(action) {
http.open('get', 'rpc.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
</script>
</head>
<style type="text/css">
body {
margin: 0px; padding:0px;
background-color: #FFFFFF;
}
</style>
<body>
<table width="1025" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" height="81">
<a href="http://www.ajaxcounter.com">
<img src="images/index_01.gif" width="138" height="81" alt="Ajax Counter" border="0"></a></td>
<td colspan="2" height="81">
<img src="images/index_02.gif" width="485" height="81" alt=""></td>
<td width="179" height="81" bgcolor="#000000">
</td>
<td width="222" height="81" bgcolor="#000000"> </td>
<td height="81">
<img src="images/spacer.gif" width="1" height="81" alt=""></td>
</tr>
<tr>
<td width="14" height="189" rowspan="4" bgcolor="#C10101">
</td>
<td colspan="2" height="1">
<img src="images/index_06.gif" width="124" height="1" alt=""></td>
<td height="1">
<img src="images/index_07.gif" width="222" height="1" alt=""></td>
<td width="442" height="55" colspan="2" rowspan="2" bgcolor="#C10101">
<img border="0" src="images/redfiller.gif" width="263" height="55" alt="Filler"></td>
<td width="222" height="189" rowspan="4" bgcolor="#C10202"> </td>
<td height="1">
<img src="images/spacer.gif" width="1" height="1" alt=""></td>
</tr>
<tr>
<td colspan="3" height="54">
<img src="images/index_10.gif" width="346" height="54" alt=""></td>
<td height="54">
<img src="images/spacer.gif" width="1" height="54" alt=""></td>
</tr>
<tr>
<td width="788" height="134" rowspan="2" bgcolor="#C10101" colspan="5" valign="top">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%">
<tr>
<td width="100%"><font face="Arial" size="2" color="#FFFFFF">
<TEXT></font></td>
</tr>
<tr>
<td width="100%"><font size="2" color="#FFFFFF" face="Arial">
<GOOGLE ADSENSE AD></font></td>
</tr>
<tr>
<td width="100%"><font face="Arial" size="2" color="#FFFFFF">
<a href="javascript:sndReq('reset')">[Reset a Counter</a>
</font>
<p><font face="Arial" size="2" color="#FFFFFF">
<div id="reset">
DEFAULT
</div>
</font></td>
</tr>
</table>
</td>
<td height="9">
<img src="images/spacer.gif" width="1" height="9" alt=""></td>
</tr>
<tr>
<td height="125">
<img src="images/spacer.gif" width="1" height="623" alt=""></td>
</tr>
<tr>
<td height="1">
<img src="images/spacer.gif" width="14" height="1" alt=""></td>
<td height="1">
<img src="images/spacer.gif" width="10" height="1" alt=""></td>
<td height="1">
<img src="images/spacer.gif" width="114" height="1" alt=""></td>
<td height="1">
<img src="images/spacer.gif" width="222" height="1" alt=""></td>
<td height="1">
<img src="images/spacer.gif" width="263" height="1" alt=""></td>
<td height="1">
<img src="images/spacer.gif" width="179" height="1" alt=""></td>
<td height="1">
<img src="images/spacer.gif" width="222" height="1" alt=""></td>
<td height="1"></td>
</tr>
</table>
</body>
</html>
Inside my RPC.PHP is this:
Code:
<?php>
switch($_REQUEST['action']) {
case 'reset':
/ do something /
echo "reset|RESET COUNTER";
break;
}
So, atm when someone clicks "Reset Counter" on the site it should change DEFAULT to RESET COUNTER under the DIV tag 'reset'. However, when I try nothing happens. This is really frustrating. Can someone please suggest what I need to do to get this working?
Thanks
