English 中文(简体)
Ajax Ron Query Upon Submit based on Radio Button Chosen
原标题:Ajax Run Given Query Upon Submit Based on Radio Button Chosen

<>光>:

<form style="margin:5px 0;" action="#" method="post"> 
            Buyer <input type="radio" name="addType" value="Buyer" />
            &nbsp;&nbsp;Merchant <input type="radio" name="addType" value="Merchant" />
        </form>
        <form id="NewBuyerRegHp" method="post" action="check.php">
            Username or Email: <input type="text" name="userOrEmail" class="UserLogin" value="Username" onFocus="clearText(this)" /> <br />
            Password: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="password" name="userPass" class="UserLogin" value="Password" onFocus="clearText(this)"  /> <br />
            <input type="submit" name="SubmitNewBuyerHp" value="Secure Login" />
        </form>

PHP

$NewBuyerLoginCheck = mysql_query("SELECT uUName, uEmail, uUPass, dynamSalt FROM User WHERE uUName OR uEmail =  ".mysql_real_escape_string($_POST[ userOrEmail ])."  AND uUPass = sha2(concat(dynamSalt,  ".mysql_real_escape_string($_POST[ userPass ])." ), 512) ")or die(mysql_error());

$NewMerchLoginCheck = mysql_query("SELECT mUsername, mEmail, mUPass, mdynamSalt FROM Merchant WHERE mUsername OR mEmail =  ".mysql_real_escape_string($_POST[ userOrEmail ])."  AND mUPass = sha2(concat(dynamSalt,  ".mysql_real_escape_string($_POST[ userPass ])." ), 512) ")or die(mysql_error());


if(mysql_num_rows == 1){
echo "Success"; 
//then redirect the users homepage
}
else(mysql_num_rows == 0){
echo "Error"; 
// then redirect to original login form, for relogin
}

When radio button: value="Buyer" is chosen, it should run query $NewBuyerLoginCheck

如果选择了无线电台: Value=“Merchant”,它就应当运行查询。 新Merch CarloinCheck

How do I do this based on the radio button selected upon submit using Ajax?

最佳回答

如果你使用 j,你可以这样做:

<script type="text/javascript" src="jquery-1.4.3.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){           
            $( #NewBuyerRegHp ).submit(function() {
                $.ajax({
                    type:  POST ,
                    url: $(this).attr( action ),
                    data: $(this).serialize(),
                    success: function(data) {
                        $( #ajax ).html(data);
                    }
                })
                return false;
            });
        });
</script>
<form id="NewBuyerRegHp" method="post" action="check.php" style="margin:5px 0;">
    Buyer <input type="radio" name="addType" value="Buyer" checked="checked" /> <!-- Default value is checked -->
    Merchant <input type="radio" name="addType" value="Merchant" /><br />
    Username or Email: <input type="text" name="userOrEmail" class="UserLogin" placeholder="Username" /> <br />
    Password: <input type="password" name="userPass" class="UserLogin" placeholder="Password"  /> <br />
    <input type="submit" name="SubmitNewBuyerHp" value="Secure Login" />
</form>
<div id="ajax"></div> <!-- Check return value if using ajax -->

医生法:

<?php
if (isset($_POST[ addType ]) && isset($_POST[ userOrEmail ]) && isset($_POST[ userPass ])){
    if($_POST[ addType ] ==  Buyer ){
        $NewBuyerLoginCheck = mysql_query("SELECT uUName, uEmail, uUPass, dynamSalt FROM User WHERE uUName OR uEmail =  ".mysql_real_escape_string($_POST[ userOrEmail ])."  AND uUPass = sha2(concat(dynamSalt,  ".mysql_real_escape_string($_POST[ userPass ])." ), 512) ") or die(mysql_error());
    } elseif($_POST[ addType ] ==  Merchant ){
        $NewMerchLoginCheck = mysql_query("SELECT mUsername, mEmail, mUPass, mdynamSalt FROM Merchant WHERE mUsername OR mEmail =  ".mysql_real_escape_string($_POST[ userOrEmail ])."  AND mUPass = sha2(concat(dynamSalt,  ".mysql_real_escape_string($_POST[ userPass ])." ), 512) ") or die(mysql_error());
    }
    if(mysql_num_rows == 1){
        echo "Success";
        //then redirect the users homepage
    } elseif(mysql_num_rows == 0){
        echo "Error";
        // then redirect to original login form, for relogin
    }
}
?>
问题回答

举例

    $( input:radio ).click(function(){
if($("input:checked").val() == "Buyer")
{
    //ajax call to php file and pass a parameter buyer
}
else{
    //ajax call to php file and pass a parameter merchant        
}
});

视参数而定,将员额价值列入《公约》的《任择议定书》编码,并按参数加以调整。





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Remotely authenticating client Windows user on demand

Suppose I am writing a server for a particular network protocol. If I know that the client is running on a Windows machine, is it possible for my server to authenticate the Windows user that owns the ...

Role/Permission based forms authorizing/authentication?

While looking into forms authorizing/authentication, I found that it is possible to do role based authorizing by adding an array of roles to a FormsAuthenticationTicket. That way I can write User....

热门标签