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.'"}';
}

ジャバスクリプトコード...

$(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