Hi all...I am new to ajax and facing an uneven problem.

I am validating login form and calling the same link (with additional parameters) through xmlhttp.open(). First the form code

<div id= "login" method="GET" >  

<form action="" id="contactform">

 <input type="image" src="login-button.jpg" name="login_user" id="button" value="Login" alt="Submit button" onclick="loadXMLDoc(username.value, password.value)"/>

</form>

<span id="txtHint"></span>

</div>

Ajax code is:

<script type="text/javascript">
function loadXMLDoc(uname, pass)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET",window.location.pathname + "?uname=" + uname + "&pass=" + pass + "&login=" + 'login', true);
xmlhttp.send();
}
// window.location.pathname = http://www.abc.com/
</script>

Now, I am getting a problem. After clicking login button, I am redirected to

http://www.abc.com/?username=sdwqd&password=www&login_user.x=11&login_user.y=3&login_user=Login

What is the problem....How can it use names of text fields and submit button as parameters in the url while I am not passing any of them...

Please help...

Recommended Answers

All 2 Replies

Your function loadXMLDoc() needs to validate its inputs BEFORE trying to create and call the XML request.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.