CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    May 2010
    Posts
    14

    Question Questions about my first AJAX script.

    hey guys!

    I finally have a working ajax script, it's from a tutorial and i have altered it to my liking.I have some questions regarding it. Here's the code.

    Code:
    <script type="text/javascript"> 
    //scanner AJAX
    function Ajax()
    {
    	var scanner;
     	try
    	{
    		scanner=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari 
    	} 
    	catch (e)
    	{ 
    		try
    		{
    			scanner=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer 
    		}
    		catch (e)
    		{
    			try
    			{
    				scanner=new ActiveXObject("Microsoft.XMLHTTP"); 
    			} 
    			catch (e)
    			{
    				alert("Your browser has no ajax support!"); return false; 
    			} 
    		} 
    	} 
    	scanner.onreadystatechange=function()
    	{ 
    		if(scanner.readyState==4)
    		{
    			document.getElementById('scanner').innerHTML=scanner.responseText;
    			setTimeout('Ajax()',2000); 
    		} 
    	} 
    	scanner.open("GET","navscanner.php",true); 
    	scanner.send(null); 
    }
    window.onload=function()
    { 
    setTimeout('Ajax()',2000); 
    } 
    </script>
    So this outputs a table inside a div in my page that i generate with navscanner.php

    Now i have a lot more div's to be filled like this. And i'm kinda stuck to where to put the new code.

    1) Do i need to make the browser check each time i do a ajax request?

    2)If i need more divs to refresh each 2 second like above code can i use the above code to make that happen or do i need a totally new function?

    3)same question as 3 but for div's that need to get loaded on start and when a player clicks something. Can i put all this code inside the Ajax function or do i need sepperate functions for each?
    Last edited by menyo; June 2nd, 2010 at 11:07 AM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured