Ajax ignores POST method
Posted: Fri Nov 06, 2009 4:02 am
I'm using AJAX to post a form to a php script for a login page i'm trying to create. The problem is that AJAX call ignores the method that i want to use for the request and uses the default html form attribute which is empty(so GET is choosed by default). So i'm just getting a refresh page effect with wrong GET values on the url (like that "www.mydomain.com/?user_name=&user_pwd=")
If i remove the form tag from html the AJAX request is working fine, but then i have problem with my html document.
Any help on this whould be appreciated..
Thanks in advance..
If i remove the form tag from html the AJAX request is working fine, but then i have problem with my html document.
Code: Select all
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$.ajax({
url:"validate_scripts/validate_login.php",
data:$("form").serialize(),
type:"post",
success:function(response,status){
alert(response+":"+status);
}
});
});
});
</script>
Code: Select all
<form id="login_frm" action="">
<table>
<caption>Insert username and password</caption>
<tr>
<td>Username</td>
<td><input type="text" name="user_name" id="user_name"/></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="user_pwd" id="user_pwd" /></td>
</tr>
<tr>
<td>Keep my identity <input type="checkbox" name="set_cookie" id="set_cookie" /></td>
<td id="loading"></td>
</tr>
<tr>
<td><button>Login</button></td>
</tr>
</table>
</form>
Thanks in advance..