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
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    new to ajax help me get this code working pls!!!

    Hi i've to combo boxes one for title ids and one for author ids... once i select title id author ids corresponding to tat title id should get loaded from the database.. i'm posting the whole code kindly help...
    Code:
    <script type="text/javascript">
    	        function getEmployee()
    	        {
    	        	xmlHttp=GetXmlHttpObject();
    	        	alert(xmlHttp);
    	        	var val=document.getElementById("projectName").value;
    	        	alert("i");
    	        	
    	        	//xmlHttp=GetXmlHttpObject();
    				if (xmlHttp==null)
    				  {
    				  alert ("Your browser does not support AJAX!");
    				  return;
    				  } 
    			var url="http://localhost:8080/timetracker2_original/Review_Timesheet1.jsp";
    			url=url+"?projname="+val;
    			url=url+"&sid="+Math.random();
    			xmlHttp.open("GET",url,true);
    			xmlHttp.onreadystatechange=function()
    			{ 
    				    var status;
    				    var statusText;
    				       try{ status = xmlHttp.status;}catch(e){document.write("Status Error "+status);}
    				       try{ statusText = xmlHttp.statusText}catch(e){document.write("StatusText Error   !!! "+statusText);}
    				       //handle processed output
    				       if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
    				               // store processed response text
    				               var getVal = xmlHttp.responseText;
    				               //document.getElementById("res").innerHTML=getVal;
    				       }
    	       		}
    			
    			xmlHttp.send(null);
    	        		        			
    			alert(url);
    	        	
    	     }   
    	         
    
    	       
    	       function GetXmlHttpObject()
    	       					{
    	       					var xmlHttp=null;
    	       					try
    	       					  {
    	       					  // Firefox, Opera 8.0+, Safari
    	       					  xmlHttp=new XMLHttpRequest();
    	       					  //document.write("XMLHttpRequest();");
    	       					  }
    	       					catch (e)
    	       					  {
    	       					  // Internet Explorer
    	       					  try
    	       					    {
    	       					    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	       					    //document.write("XMLHttpRequest2();");
    	       					    }
    	       					  catch (e)
    	       					    {
    	       					    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	       					    document.write("XMLHttpRequest3();");
    	       					    }
    	       					  }
    	       					return xmlHttp;
    					}
    					
    					
    	       
    	       
    	        </script>

    This code is inside the jsp page mentioned in the url varialbe i.e., Review_Timesheet1.jsp
    Last edited by learner86; 10-19-2007 at 07:42 AM. Reason: jsp code accessing this is: String s1=request.getParameter("projname");

  • #2
    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
    And you failed to say what your problem is.

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

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    This bit:
    Code:
    	var status;
    	var statusText;
    	try{ status = xmlHttp.status;}catch(e){document.write("Status Error "+status);}
    	try{ statusText = xmlHttp.statusText}catch(e){document.write("StatusText Error   !!! "+statusText);}
    is not good. Bad choices for variable names, will cause errors rather than check for them and, unless this script is ran as the page is rendered, document.write will open a new document.
    The use of document.write in the GetXmlHttpObject() is not a good idea either. Alert it if you need to see what IE is doing.
    IE7 does support native requests.


  •  

    Posting Permissions

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