Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
Ajax + java Servlet

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help
View previous topic :: View next topic  
Author Message
lholmquist
New one
New one


Joined: 17 Jul 2006
Posts: 2
Location: Latham,ny

PostPosted: Mon Jul 17, 2006 8:52 pm    Post subject: Ajax + java Servlet Reply with quote

I'm trying to load 2 table fields asynchronusly. in my javascript i have 2 seperate xmlHttp variables that are set as xmlHttpRequest objects and 2 differnt callback functions. i am however using the same servlet for my url.

i am having problems updating my jsp page<div> with one of the callbacks

the javascript call seems to work ok. if i step through the code both of the serlvet does run twice.


the code is below. do i need to do something special to run 2 callbacks at once with the same servlet

Code:

//Javascript code


var xmlHttp
var xmlHttp2

var vload = "Loading data....Please Wait"



function doAsynchLoad(str)
{
   xmlHttp=GetXmlHttpObject()
   xmlHttp2=GetXmlHttpObject()
   if (xmlHttp==null)
   {
      alert ("Browser does not support HTTP Request")
      return
   }
   
   
   if(str == "ad")
      {
         var url="servlet/AsynchProcessServlet?action=ad"
          xmlHttp.onreadystatechange=auditDates
         xmlHttp.open("GET",url,true)
         xmlHttp.send(null)
      }
   else if(str == "usrs")
      {
         var url2="servlet/AsynchProcessServlet?action=usrs"
         xmlHttp2.onreadystatechange=users
         xmlHttp2.open("GET",url2,true)
         xmlHttp2.send(null)
      }
      

      
}



function auditDates()
{

   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
      alert("Hi inloaded")
      document.getElementById("aud").innerHTML=xmlHttp.responseText
      
   }
   else
   {
   alert("Hi in not loaded")
      document.getElementById("aud").innerHTML=vload
   }
}


function users()
{
   if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")
   {
      document.getElementById("usrs").innerHTML=xmlHttp2.responseText
   }
   else
   {
      document.getElementById("usrs").innerHTML=vload
   }
}



function GetXmlHttpObject()
{
   var objXMLHttp=null
   if (window.XMLHttpRequest)
   {
      objXMLHttp=new XMLHttpRequest()
   }
   else if (window.ActiveXObject)
   {
      objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
   }
   return objXMLHttp
}


//Part of the servlet code

if(request.getParameter("action").equals("ad"))
      {
      
         response.setContentType("text/html");
         response.setHeader("Cache-Control","no-cache");
         PrintWriter out = response.getWriter();
         
         List auditDates = new ArrayList();
         
         auditDates = c.getAuditDates();
         DateInfo dateInfo = new DateInfo();
         
         Iterator it = auditDates.iterator();
         

   
      out.print("<Select name=\"ad\">");
      
      while(it.hasNext())
      {
         dateInfo = (DateInfo)it.next();
         
         if(dateInfo.getClosedB().equals("N"))
         {
            out.print("<option value=\""+dateInfo.getAuditDate()+"\" selected=\"selected\">");
            out.print(dateInfo.getAuditDate()+"**</option>");
         }
         else
         {
            out.print("<option value=\""+dateInfo.getAuditDate()+"\" >");
            out.print(dateInfo.getAuditDate()+"**</option>");
         }
      }
         
      out.print("</select>");
      
      out.flush();
      out.close();

      
      }
      else if(request.getParameter("action").equals("usrs"))
      {
         response.setContentType("text/html");
         response.setHeader("Cache-Control","no-cache");
         PrintWriter out = response.getWriter();
         
         
         List securityUser = new ArrayList();
         
         ADInfo adinfo = new ADInfo();
         
         securityUser = adinfo.getSecurityUsers();
         
         //Get the security users that are in the table but not in security group
         securityUser = c.getOtherSecureUsers(securityUser);
         
         //Add securityUserlist to session
         
         SecurityGuardInfo securityInfo = new SecurityGuardInfo();
         
         Iterator it = securityUser.iterator();
         
         out.print("<select id=\"securityUser\" name=\"securityUser\"");
         out.print("<option value\"All\">All Security User's</option>");
         
         while(it.hasNext())
         {
            securityInfo = (SecurityGuardInfo)it.next();
            
            out.print("<option value=\""+securityInfo.getUsername()+"\">");
            out.print(securityInfo.getUsername()+"</option>");
            
         }
         
         out.print("</select>");
         
         out.flush();
         out.close();
      }


//Part of the jsp

<td><div id="aud">&nbsp;
<script language="javascript">doAsynchLoad('ad')</script>
</div>
</td>
</tr>

<tr>
<td>Security User's</td>
<td><div id="usrs">&nbsp;
<script language="javascript">doAsynchLoad('usrs')</script>
</div>
</td></tr>

Back to top
View user's profile Send private message
Snyke
Forum Assistant
Forum Assistant


Joined: 20 Jun 2006
Posts: 87
Location: Zurich

PostPosted: Mon Jul 17, 2006 10:47 pm    Post subject: Reply with quote

This should not be an issue as you define two different callback function for the two XHR they should not interfere. The Servlet doesn't do anything special, and it is definitely not the fault of it.
If you are using FireFox I'd suggest you to install the Firebug extension ( https://addons.mozilla.org/firefox/1843/ ) and see what calls are fired and what does come back from the server. You may need to debug your code (again Firebug).
That information may be usefull for us too, to help you should you be unable to fix the problem.
_________________
[::[ Snyke.net ]::]
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
lholmquist
New one
New one


Joined: 17 Jul 2006
Posts: 2
Location: Latham,ny

PostPosted: Tue Jul 18, 2006 1:50 am    Post subject: Reply with quote

thanks for the reply, i set up an alert box for the status inside the callback functions and i noticed that when the first one is called it is set to 1 then when the second is called the first ones status goes to 0 while the second functions status progresses to 4

i am using IE 6
Back to top
View user's profile Send private message
Snyke
Forum Assistant
Forum Assistant


Joined: 20 Jun 2006
Posts: 87
Location: Zurich

PostPosted: Tue Jul 18, 2006 10:45 pm    Post subject: Reply with quote

Wow, that looks really strange indeed, assuming that the implementation of IE is correct this should not happen, as the object should not interfere one with another...

Did you try a library such as Prototype? They usually eliminate the need for such low level tweaking...
_________________
[::[ Snyke.net ]::]
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert