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 3 of 3
  1. #1
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post

    Display loading icon while script is working

    Code:
    // JavaScript Document
    function getXMLHTTP() { //fuction to return the xml http object
    		var xmlhttp=false;	
    		try{
    			xmlhttp=new XMLHttpRequest();
    		}
    		catch(e)	{		
    			try{			
    				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
    			}
    			catch(e){
    				try{
    				req = new ActiveXObject("Msxml2.XMLHTTP");
    				}
    				catch(e1){
    					xmlhttp=false;
    				}
    			}
    		}
    		 	
    		return xmlhttp;
        }
    function getSubCat(categoryid,selected)
    {
    	var strUrl = "ajax.php?categoryid="+categoryid+"&selcat="+selected+"";
    	var req	=	getXMLHTTP();
    	if(req)
    	{
    		req.onreadystatechange  = function()
    		{
    			if(req.readyState == 4)
    			{
    				if(req.status == 200)
    				{
    					document.getElementById('divsubcat').innerHTML = req.responseText;
    				}
    				else
    				{
    					alert("There was a problem while using XMLHTTP \n"+req.statusText);
    				}
    			}
    		}
    		req.open("GET", strUrl, true);
    		req.send(null);
    	}
    }
    The code above connects two list menus. It opens different list menu according to what is selected in second. But sometimes it takes several seconds to change the list when the selection is changed. How can I display loading icon during this time?

    Thanks in advance

  • #2
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    Sorry for double posting...

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Before you call send show a hidden image on the page. When the response comes back you hide the image.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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