The ajax below is perfectly working in chrome, IE, opera and safari. But it is, somehow not working in firefox. It says reference error, event is not defined. I tried using event.preventDefault() instead of return false too, surely no luck for me. When the submit button is clicked, in firefox the page is jumped to loginCheck.php and shows success. But that is not the way I meant to do, the message 'success' should be returned in the same page itself rather than jumping to another page and showing the message in another page.
FORM IS LIKE THIS:
<form id="loginForm" class="ajax" action="ajax/loginCheck.php" style="padding-left: 10px;" method="post">
Username: <br/>
<input name="username" class="required" type="text"> <br/>
<span class="small">
<a class="mouseOver forgot" href="include/recover.php?mode=u_name">Forget username ?</a>
</span><br/>
Password: </br>
<input name="password" class="required" type="password"> <br/>
<span class="small">
<a class="mouseOver forgot" href="include/recover.php?mode=u_password">Forget password ?</a>
</span><br/>
<input type="submit" class="button" value="sign in">
//when login button is clicked
(function(){
$('form.ajax').on('submit' , function(){
//alert('about to pass data');
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {}; //declaration of data of array type
that.find('[name]').each(function(index, value){
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function(response){ //code to run if request success
var result = $.trim(response);
console.log(response);
if(result == "success"){
$('#interaction').load('interaction.php'); //load logout icong
$('#rightbar').load('rightbar.php'); //load user panel
$('.loginCheck').html("");
}else{
$('.loginError').show();
$('.loginError').html(response);
}
}
});
return false;
});
})();