SoFunction
Updated on 2025-04-05

Bind Enter event code


function sendLoginData(){
loginvalidateForm();

$(document).keydown(function(event){
if( == 13){ //Bind to enter
$('#login-submit').click(); /auto/trigger login button
}
});

$('#login-submit').click(function(){
if($('#login-form').valid()==false){
return false;
}

var username = $('#id_username').val();
var password = $('#id_password').val();
$.ajax({
type:"post",
dataType:"json",
contentType:"application/x-www-form-urlencoded;charset=UTF-8",
url:"{% url %}",
data:{
username: username,
password: password
},
beforeSend: function(){
// Prompt information to improve user experience
$('#loginInfoWord').show().text('Processing, please wait...');
},
success:function(data){
var message = ;
if(message == 'D'){
// Prompt information to improve user experience
$('#loginInfoWord').show().text('Login successfully, jumping...');
= '{% url %}';

}else if(message == 'C'){
$('#loginInfoWord').show().text('Username or password is incorrect');
}else if(message == 'N'){
$('#loginInfoWord').show().text('You are not registered yet!');
}else if(message == 'H'){
$('#loginInfoWord').show().text('You have not activated your account yet, log in to your email to activate your account!');
}
},
error: function(xhr,textStatus,errorThrown){
$('#loginInfoWord').show().text('Exception occurred:'+errorThrown);
}

});

});

/* It's OK to put it on the top and bottom, it has nothing to do with the order

$(document).keydown(function(event){
if( == 13){ //Bind to enter
$('#login-submit').click(); /auto/trigger login button
}
});

*/
}