0

我的代码有问题...如果实现了 javascript,函数 retmsg 没有返回值

<div id="pop">
    <a href="#" class="title">Elunika</a>
    <div class="txt">Its the way to connect with your friends.</div>
    <form action="login.php" method="post" id="login">
        <input id="email" placeholder="E-mail" type="text" name="em" />
        <input id="email" placeholder="Password" type="password" name="pwd"/>
        <div class="txt1"><input type="checkbox" name="check" />Keep me logged in |<a href="#"> Forgot Password ?</a></div>
        <input id="loginButton" type="submit" value="Login" name="log" />
    </form>
    <a href="#" id="reg"><span>Register</span></a>
    <div id="error1"></div>
    <div id="termdiv1"></div>
</div>

从 retmsg() 函数返回的值应显示在 div id="error" 中

登录脚本...

if (isset($c))
{
    $q = mysql_query("select * from registeration where email='$a' and password='$b'");
    $r = mysql_num_rows($q);

    if($r)
    {
        $_SESSION["Authenticated"] = 1;
        $_SESSION['id'] = $a;
        echo retmsg(1,"profile.php");
    }
    else
    {
        $_SESSION["Authenticated"] = 0;
        die (retmsg(0,"Incorrect Information"));
    }
}
function retmsg($status,$txt)
{
    return '{"status":'.$status.',"txt":"'.$txt.'"}';
}

javascript代码...

$(document).ready(function(){
    $('#login').submit(function(e) {
        att();
        e.preventDefault();
    });
    $('#regForm').submit(function(e) {
        register();
        e.preventDefault();
    });
});


function register()
{
    hideshow('loading',1);
    error(0);

    $.ajax({
        type: "POST",
        url: "submit.php",
        data: $('#regForm').serialize(),
        dataType: "json",
        success: function(msg){
            if(parseInt(msg.status)==1)
            {
                window.location=msg.txt;
            }
            else if(parseInt(msg.status)==0)
            {
                error(1,msg.txt);
            }

            hideshow('loading',0);
        }
    });

}


function hideshow(el,act)
{
    if(act) $('#'+el).css('visibility','visible');
    else $('#'+el).css('visibility','hidden');
}


function error(act,txt)
{
    hideshow('error',act);
    if(txt) {
        $('#error').html(txt);
        $('#regpop').css('height','419px');
        $('#termdiv').css('margin-top','10px');
    }
    if(!txt) {
        $('#regpop').css('height','400px');
        $('#termdiv').css('margin-top','-20px');
    }
}


function att()
{
    hideshow1('loading',1);
    error1(0);
    $.ajax({
        type: "POST",
        url: "login.php",
        data: $('#login').serialize(),
        dataType: "json",
        success: function(retmsg){
            if(parseInt(retmsg.status)==1)
            {
                window.location=retmsg.txt;
            }
            else if(parseInt(retmsg.status)==0)
            {
                error1(1,retmsg.txt);
            }

            hideshow1('loading',0);
        }
    });
}


function hideshow1(el,act)
{   
    if(act) $('#'+el).css('visibility','visible');
    else $('#'+el).css('visibility','hidden');
} 


function error1(act,txt)
{
    hideshow1('error1',act);
    if(txt) {
        $('#error1').html(txt);
        $('#pop').css('height','290px');
        $('#termdiv1').css('margin-top','50px');
    }
    if(!txt) {
        $('#pop').css('height','270px');
        $('#termdiv1').css('margin-top','-35px');
    }
}

在 javascript 代码中,retmsg 应该将 txt 参数返回给 att 函数..... att 函数正在将 retmsg.txt 值传递给 error1 函数,函数 error1 的一部分正在工作,因为 retmsg.txt 没有返回值...

其余的 javascript 代码工作正常……其余代码与此相同……只是函数名称不同……

回答*回答*回答

javascript 代码都是正确的 在登录脚本中进行了更改

$q = mysql_query("select * from registeration where email='$a' and password='$b'");
$r = mysql_num_rows($q);

if(!$r)
{
    $_SESSION["Authenticated"] = 0;
    die (retmsg(0,"Incorrect Information"));
}
else
{
     $_SESSION["Authenticated"] = 1;
     $_SESSION['id'] = $a;
     echo retmsg(1,"profile.php");
 }

function retmsg($status,$txt)
{
return json_encode(array('status' => $status, 'txt' => $txt));
}
4

0 回答 0