hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Simple Ajax in my site does not seem to be working, please please please help!
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Simple Ajax in my site does not seem to be working, please please please help!

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 11-25-2005, 07:56 AM
Hostex Australia Hostex Australia is offline
Web Hosting Master
 
Join Date: Feb 2004
Location: Australia (Crikey)
Posts: 2,271
Unhappy

Simple Ajax in my site does not seem to be working, please please please help!


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">

			&nbsp;</td>
		<td width="222" height="81" bgcolor="#000000">&nbsp;</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">
			&nbsp;</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">&nbsp;</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">
                &lt;TEXT&gt;</font></td>
              </tr>
              <tr>
                <td width="100%"><font size="2" color="#FFFFFF" face="Arial">
                &lt;GOOGLE ADSENSE AD&gt;</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

Reply With Quote


Sponsored Links
  #2  
Old 11-25-2005, 08:12 AM
Hostex Australia Hostex Australia is offline
Web Hosting Master
 
Join Date: Feb 2004
Location: Australia (Crikey)
Posts: 2,271
I've tried some different code and it is still not working *cries*

Reply With Quote
  #3  
Old 11-25-2005, 08:37 AM
X-TechMedia X-TechMedia is offline
Junior Guru
 
Join Date: Nov 2002
Location: United Kingdom
Posts: 247
The code you posted above works fine for me. The only thing I changed was the rpc.php to

PHP Code:
<?php
switch($_REQUEST['action']) {
    case 
'reset':
    echo 
"reset|RESET COUNTER";
    break;
}
?>

__________________
Ben Periton

Reply With Quote
Sponsored Links
  #4  
Old 11-25-2005, 08:43 AM
Hostex Australia Hostex Australia is offline
Web Hosting Master
 
Join Date: Feb 2004
Location: Australia (Crikey)
Posts: 2,271
Okay well I will change back to the original code, however when I tried to click RESET COUNTER nothing would happen (firefox) and IE would give a javascript error on Line 47.

Reply With Quote
  #5  
Old 11-25-2005, 08:53 AM
Hostex Australia Hostex Australia is offline
Web Hosting Master
 
Join Date: Feb 2004
Location: Australia (Crikey)
Posts: 2,271
Okay I reverted back and it is now working. I must say I am extremely pleased with the way Ajax works

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Web Hosting Talk Message Board Back Online Following DDoS Attack Web Hosting News 2012-09-12 11:59:42
Shopping Cart Software Ecwid Expands Reseller Program, Targets Web Hosts Web Hosting News 2012-05-15 11:47:26
Q&A: Ruslan Fazlyev of Ecwid Talks Shopping Cart Software Web Hosting News 2012-05-14 16:06:17
WordPress Host WP Engine Launches Checkpoint Restore Tool Web Hosting News 2012-01-30 12:33:23
Security Firm GeoTrust Launches Website Anti-Malware Scan Service Web Hosting News 2011-10-20 17:23:34


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?