
i m not able to compare string with the responseText value, though the value in the responsetext is of string type. my code: login.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
var showdata;
function fun(a,b){
xmlHttp=GetXmlHttpObject()
var url="process_login.jsp";
url=url+"?name="+a+"&pwd="+b;
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
showdata = xmlHttp.responseText;
if(showdata == "done") //something wrong here..
{
document.getElementById("msg").innerHTML= showdata
}else{document.getElementById("msg1").innerHTML= showdata}
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body>
<h2>Login</h2>
<table border="0">
<tr>
<td>username:
<td><input type="text" name="lnm" id="lnm"/>
</tr>
<tr>
<td>password:
<td><input type="text" name="lpwd" id="lpwd"/>
</tr>
</table>
<input type="button" name="bt" id="bt" onclick="fun(document.getElementById('lnm').value,document.getElementById('lpwd').value);" value="login"/>
<div id="msg"></div><br><br><br>
<font color="red"><div id="msg1"></div></font>
</body>
</html>
process_login.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<%
out.println("done");
%>
</body>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.