...

View Full Version : Ajax xml login help



reader
03-19-2011, 06:46 PM
I wrote the following code that is a login form for user accounts stored in xml files but when i try to login no popup box shows up could someone please tell me what I did wrong


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<style type=text/css>
</style>

<script type=text/javascript>
function login(){
var xmlhttp;
var login=document.getElementById("login");
var xmlDoc=xmlhttp.responseXML;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","/users/" + login.elements[0].value + ".xml", true);
xml.send();
if (xmlDoc.getElementByTagName("username")==login.elements[0].value)
{
if (xmlDoc.getElementByTagName("password")==login.elements[1].value)
{
alert ("You have entered the correct username and password");
}
else
{
alert ("Incorrect username or password");
}
}
else
{
alert("Incorrect username or password");
}
</script>



</head>
<body>
<div id=login>
<form name=login id=login>
Username: <input type=text name=login_username id=username />
<br />
Password: <input type=password name=login_pass id=password />
<br />
<input type=submit class=button value=Submit onClick=javascript.login() />
</form>
</div>

<style language=javascript>
</style>

</body>
</html>

MarPlo
03-20-2011, 04:18 PM
Hy,
getElementByTagName("password") contains an array of all tags "password"
Try getElementByTagName("password")[0]
Also, the values of attributes in the html form should be within quote id="password" and the others.
If still don't works, see the examples from Ajax and XML (http://www.coursesweb.net/ajax/ajax-xml) tutorial.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum