Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Ajax append

  1. #1
    Regular Coder primefalcon's Avatar
    Join Date
    Aug 2008
    Location
    /home/primefalcon/
    Posts
    678
    Thanks
    8
    Thanked 39 Times in 39 Posts

    Ajax append

    I have the following script that returns a simple php echo from a php script echo date("H:i:s"); to be precise, which is working fine.

    what I want to know how to do though, is how to append date instead of replacing it

    for example instead of just replacing

    data

    with

    new data

    how to make it add the new data to the old like old data, new data

    and I'm not sure how to do this, can someone help please


    here's the script

    Code:
    <html><head>
    <title>Ajax test</title>
    <script langauge="JavaScript">
    var request = null;
    
    
    function createRequest()
    		{
    			try
    				{
    					request = new XMLHttpRequest();
    				} 
    					catch(trymicrosoft)
    						{
    							try
    								{
    									request = new ActiveXObject("Msxml2.XMLHTTP");
    								}
    									catch(othermicrosoft)
    										{
    											try
    												{
    													request = new ActiveXObject("Microsoft.XMLHTTP");
    												}
    													catch(failed)
    														{
    															request = null;
    														}
    										}
    																			
    					
    						}
    						
    
    						
    											
    
    						
    			
    							
    			}</script>
    </head><body>
    <script langauge="JavaScript">
    
    
    function updatePage()
    				{
    					if(request.readyState == 4)
    						{
    							var newData = request.responseText;
    							document.getElementById("pagedisplay").innerHTML = newData;
    
    							
    						}
    					
    				}
    
    function main()
    	{
    		createRequest();
    		var serverurl = "http://localhost/ajaxtest/server.php";
    		request.open("GET", serverurl, true);
    		request.onreadystatechange = updatePage;
    		request.send(null);
    		setTimeout('main()', 1);
    
    	}
    
    setTimeout('main()', 250);
    
    </script>
    <div id="pagedisplay"></div>
    
    
    
    </body></html>
    Last edited by primefalcon; 11-17-2008 at 05:56 AM.

  • #2
    Regular Coder primefalcon's Avatar
    Join Date
    Aug 2008
    Location
    /home/primefalcon/
    Posts
    678
    Thanks
    8
    Thanked 39 Times in 39 Posts
    Nvm I worked it out myself

    Code:
    <html><head>
    <title>Ajax test</title>
    <script langauge="JavaScript">
    var request = null;
    
    
    function createRequest()
    		{
    			try
    				{
    					request = new XMLHttpRequest();
    				} 
    					catch(trymicrosoft)
    						{
    							try
    								{
    									request = new ActiveXObject("Msxml2.XMLHTTP");
    								}
    									catch(othermicrosoft)
    										{
    											try
    												{
    													request = new ActiveXObject("Microsoft.XMLHTTP");
    												}
    													catch(failed)
    														{
    															request = null;
    														}
    										}
    																			
    					
    						}
    						
    
    						
    											
    
    						
    			
    							
    			}</script>
    </head><body>
    <script langauge="JavaScript">
    
    
    function updatePage()
    				{
    					if(request.readyState == 4)
    						{
    							var newData = request.responseText;
    							var olddata = document.getElementById("pagedisplay").innerHTML;
    							var Display = olddata + "<br />" +newData;
    							document.getElementById("pagedisplay").innerHTML = Display;
    							
    							
    						}
    					
    				}
    
    function main()
    	{
    		createRequest();
    		var serverurl = "http://localhost/ajaxtest/server.php";
    		request.open("GET", serverurl, true);
    		request.onreadystatechange = updatePage;
    		request.send(null);
    		setTimeout('main()', 500);
    
    	}
    
    setTimeout('main()', 250);
    
    </script>
    <div id="pagedisplay"></div>
    
    
    
    </body></html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •