Hi,I am trying to implement ajax for authenticating the login credentials. onkeyup() event ,i invoke a js function validate() as below:
function validate() {
alert("hey here..");
var idField = document.getElementById("userName");
alert(idField.value);
var pwdField = document.getElementById("password");
alert(pwdField.value);
var url = "/Login.do?userName=" + escape(idField.value)+"pwd=" + escape(pwdField.value);
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
alert("xmlhttp: "+req.value);
} else if (window.ActiveXObject) {
alert("xmlhttp: "+req);
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET", url, true);
req.onreadystatechange = callback;
req.send(null);
}
But i get a js error tha says XMLHttpRequest object is
undefined.I am using IE6.0 and the webserver is tomcat6.0.18.
I set the below headers in the
servlet called:
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write(“exists");
When i get the response from the server,callback() function is called.
function callback() {
alert("from callback");
if (req.readyState == 4) {
if (req.status == 200) {
// parse the response and get the message
message = req.getResponseText;
mdiv = document.getElementById("userIdMessage");
if (message == "exists")
{
mdiv.innerHTML = "<div style=\"color:red\">User Id exists</ div>";
} else {
mdiv.innerHTML = "<div style=\"color:green\">Valid User Id</ div>";
}
}
}
}