伙计们,使用以下代码:
$(document).ready(function() {
$(".list-book-description").css("display", "none");
$("#user-panel-login").css("display", "none");
$('#login-form').submit(function(e) {
e.preventDefault();
var formUsername=$("#login-form #username").val();
var formPassword=$("#login-form #password").val();
if((formUsername.length<6))
{
$("#ajax-output").html("<div class='error'>Attenzione username troppo breve!</div>");
}
else if((formPassword.length<6))
{
$("#ajax-output").html("<div class='error'>Attenzione password troppo breve!</div>");
}
else
{
$.post(
'index.php?module=login',
{
"username": formUsername,
"password": formPassword,
},
function(data){
$("#ajax-output").html(data);
}
);
}
});
});
我试图将?index.php&module=login&function=1
用户名和密码传递给#login-form
字段#username
和使用函数#password
的login()
php 函数,setLogin();
如果数据进入数据库来设置登录会话。
function Login()
{
if(!checkLogin())
{
$function=@stringEscape($_GET['function']);
if($function==1)
{
$username=stringEscape($_POST['username']);
$password=sha1(stringCrypt($_POST['password'], 'sha1').stringCrypt(DB_CRYPT, 'sha1'));
if(setLogin($username, $password))
{
echo "<div class='ok'>Login effettuato con successo, tra pochi secondi verrai riportato alla homepage!</div>";
}
}
}
else notfound();
}
function setLogin($username, $password, $time="")
{
if(!checkLogin())
{
if((isset($username)) && (isset($password)))
{
$query=mysql_query("SELECT * FROM ".DB_PREF."users WHERE user_username='".$username."' AND user_password='".$password."'");
if(mysql_num_rows($query))
{
$fetch=mysql_fetch_assoc($query);
$_SESSION['logged_user_id']=$fetch['user_id'];
$_SESSION['logged_user_username']=$fetch['user_username'];
return true;
}
else
{
echo "<div class='error'>Dati non validi, ripeti la procedura di login o <a href='?index.php&module=registration'>registrati</a>!</div>";
}
}
}
else notfound();
}
现在当我$.post()
在我的#ajax-input
div 中获得提交登录表单的结果时,我遇到了一个问题,它不仅返回登录函数的结果,而且返回索引页面+登录函数的结果。
如果我尝试将“json”参数设置为$.post
函数并且echo json_encode()
在 php 函数中它根本不起作用。那么,可能是什么问题?