0

how to create login page using ajax?
i know whether to show valid or invalid in the same page..........
but how to redirect to same different page wen its and valid?

3
Contributors
8
Replies
11
Views
7 Years
Discussion Span
Last Post by shiv0013
0

It's something like this:

document.location('approved.php');

Edited by kishan112: n/a

0

window.location='approved.php';

document is used when working on the page, window is needed to manipulate frames or windows refreshing and redirection etc...

Edited by wrivera: n/a

0

sorry i forgot to mention that i am using html
this is my code

var xmlHttp=null;
	
	function getResult() {

		var name,password;
		name=document.login_frm.uname.value;
		password=document.login_frm.pwd.value;
		
		xmlHttp = GetXmlHttpObject();
		
		if (xmlHttp == null) {
			alert("Your browser does not support AJAX!")
			return;
		}

		var url = "/Login";
		url = url + "?q=" + name ;
		
		xmlHttp.onreadystatechange = stateChanged;
		
		xmlHttp.open("GET", url, true);
		
		xmlHttp.send(null);
	}
	function stateChanged() {
		if (xmlHttp.readyState == 4) {
			//document.writeln(xmlHttp.responseText);
			document.getElementById("Error").innerHTML = xmlHttp.responseText;
			
		}
	}

	function GetXmlHttpObject() {
		//var xmlHttp = null;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp = new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return xmlHttp;
	}
String name = request.getParameter("q");
		
		PrintWriter out = response.getWriter();	
       
		 Connection con = null;
		 PreparedStatement pstmt = null;
		 String query = null;
		 ResultSet rs=null;
		 query="select * from login where uname=? and pwd=?";
		 try{
				con=DBConnection.getInstance().getConnection();
				pstmt = con.prepareStatement(query);
				int cnt=1;
				pstmt.setString(cnt++,name);
				
				rs = pstmt.executeQuery();
				if(rs.next()){
					response.getWriter().write("valid");
					} else {
					response.getWriter().write("invalid");
								}
			}catch(SQLException e){
				e.printStackTrace();
						}
			out.close();
0

You can change this

if(rs.next()){					response.getWriter().write("valid");					} else {					response.getWriter().write("invalid");								}

into this:

if(rs.next()){					response.getWriter().write("valid");
                window.location("loginsucces.html");
					} else {					response.getWriter().write("invalid");								}
0

You can change this

if(rs.next()){					response.getWriter().write("valid");					} else {					response.getWriter().write("invalid");								}

into this:

if(rs.next()){					response.getWriter().write("valid");
                window.location("loginsucces.html");
					} else {					response.getWriter().write("invalid");								}

no that wont work becuase the server code is java and your writing in javascript.

You will have to write the window.location='page'

on your handler function like so

function stateChanged() {
   if (xmlHttp.readyState == 4) {
      if(xmlHttp.status==200){
        if( xmlHttp.responseText=="valid"){
           window.location='pagetogoto if valid';
      }
   }
  }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.