Results 1 to 2 of 2

Thread: jsp + ajax

  1. #1
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default jsp + ajax

    index.jsp
    Java Code:
    <html>
    	<head>
    		<script language="javascript">
    		function checkUsername(keyEvent){
    			keyEvent = (keyEvent) ? keyEvent : window.event;
    			input = (keyEvent.target) ? keyEvent.target : keyEvent.srcElement;
    			
    			if(keyEvent.type == "keyup"){
    				var targetDiv = document.getElementById("targetDiv");
    				if(input.value){
    					getData("login.jsp?qu="+input.value);
    				}
    			}			
    		}		
    		
    		function getData(dataSource){
    			if(XMLHttpRequestObject){
    				XMLHttpObject.open("GET", dataSource);
    				XMLHttpRequestObject.onreadystatechange == function(){
    					if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200){
    						if(XMLHttpRequestObject.responseText == "taken"){
    							var targetDiv = document.getElementById("targetDiv");
    							targetDiv.innerHTML = '<div>That Username Is Taken/div>';
    						}
    					}
    				}
    				XMLHttpRequestObject.send(null);
    			}
    		}
    		</script>
    	</head>
    	<body>
    	<form id="form1" name="form1" method="POST">
    	  <p>username : 
    		<input name="username" type="text" id="username" onkeyup="checkUsername(event)" /><div id="targetDiv"><div></div></div>
    	  </p>
    	  <p>password : 
    		<input name="password" type="text" id="password" />
    	  </p>
    	</form>
    	</body>
    </html>
    login.jsp
    Java Code:
    <%
      String username = request.getParameter("qu");
      if(username.equals("steve")){
      	out.print("taken");
      }
      else{
        out.print("ok");
      }
    %>
    does ajax doesn't return error? (javascript I mean)
    this doesn't work for me

  2. #2
    arun9683 is offline Member
    Join Date
    Jun 2010
    Location
    Bangalore,India
    Posts
    70
    Rep Power
    0

    Default

    Ajax is asynchronous it will not work synchronusly..
    Arun K R,Bangalore,India
    :)

Similar Threads

  1. Ajax
    By mallik in forum Advanced Java
    Replies: 3
    Last Post: 11-07-2009, 03:25 PM
  2. Jsp with Ajax
    By sundarjothi in forum JavaServer Pages (JSP) and JSTL
    Replies: 16
    Last Post: 09-25-2008, 10:29 AM
  3. AJAX in JSP
    By haiforhussain in forum JavaServer Pages (JSP) and JSTL
    Replies: 8
    Last Post: 07-01-2008, 02:12 PM
  4. Example for Ajax-JSP
    By smrithi in forum JavaServer Pages (JSP) and JSTL
    Replies: 8
    Last Post: 06-02-2008, 02:00 PM

Posting Permissions

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