DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Shoutbox not reloading

    I've built a shoutbox as my first AJAX project. I have two pages. For simplicity's sake of this post we'll say the shoutbox will only display the two most recent messages.

    First Page (serverprint.asp):
    Asp page that outputs the following string into the body:
    10/17/2009 10:07:18 AM'Chuckycharms'please by the freak of nature work'10/16/2009 11:32:16 PM'Chuckycharms'try it now'

    Second Page (default2.asp):
    Javascript/AJAX code that displays and updates messages every 1000ms.

    HTML Code:
    <table>	
        <tr>
          <td bgcolor="#666666"><div id="gamer1"><? echo $gamer_1; ?></div>:<div id="message1"><? echo $message_1; ?></div>--<div id="time1"><? echo $time_1; ?></div></td>
        </tr>
        <tr>
          <td bgcolor="#999999"><div id="gamer2"><? echo $gamer_2; ?></div>:<div id="message2"><? echo $message_2; ?></div>--<div id="time2"><? echo $time_2; ?></div></td>
        </tr>
    </table>
    Code:
    <script type="text/javascript">
    	var getv=-1;
    	var page="http://www.xxx.com/shoutbox/serverprint.asp";
    	
    	function getData(){
    		while(getv!=-1){}
    			if (window.XMLHttpRequest) {
    				getv= new XMLHttpRequest();
    			if (getv.overrideMimeType){
    				getv.overrideMimeType("text/xml");
    			}
    			}else if (window.ActiveXObject) {
    				try {
    					getv = new ActiveXObject("Msxml2.xmlHttp");
    					getv.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    				}catch (e) {
    				try {
    					getv= new ActiveXObject("Microsoft.xmlHttp");
    				}catch (e) {}
    				}
    			}
    			ret=-1;
    			getv.onreadystatechange = function(){
    				if (getv.readyState == 4) {
    					ret=getv.responseText;
    					update(ret);
    					getv=-1;
    				}
    			};
    			getv.open("POST", page);
    			try{
    				getv.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    			}catch(e){}
    				getv.send("");
    				return ret;
    
    				return 0;
    				setTimeout("getData()",1000);
    			}
    
    			function update(value){
    				var data=value.split("'");
    				document.getElementById("gamer1").innerHTML=data[0];
    				document.getElementById("message1").innerHTML=data[1];
    				document.getElementById("time1").innerHTML=data[2];
    				document.getElementById("gamer2").innerHTML=data[3];
    				document.getElementById("message2").innerHTML=data[4];
    				document.getElementById("time2").innerHTML=data[5];
    			}
    			window.onload = getData;
    </script>
    Page 2 initially loads the information correctly but does not attempt to update it every second. I am a beginner at AJAX so don't over-estimate my abilities and assume I am ignorant.

  2. #2
    Join Date
    Oct 2009
    Posts
    2
    Disregard this I just realized I was using setTimeout and not setInterval.

Similar Threads

  1. Replies: 0
    Last Post: 09-28-2005, 10:22 AM
  2. javascript menu reloading
    By csinar in forum Web
    Replies: 1
    Last Post: 06-03-2002, 04:01 PM
  3. Reloading in a separate window.
    By Steve in forum Web
    Replies: 1
    Last Post: 01-26-2001, 11:32 AM
  4. reloading an applet with Netscape
    By yann LE PAGE in forum Java
    Replies: 1
    Last Post: 05-11-2000, 01:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links