Jquery,ajax发布并获得结果?

时间:2013-07-22 02:08:11

标签: jquery mysql ajax post get

我正在登录,我希望ajax将每个关键笔划发布到查询中。当登录与数据库中的登录(mySQL)匹配时,我希望将密码返回到父页面。这就是现在。我过去使用ajax将php发布到数据库,但从来没有必要返回一个变量。我也不知道我是否正在传递表单信息,谢谢!

index.php脚本:

$(function(){

    $("#inputEmail").keyup(function() {
    var UsernameInput = $(this).val();
        $.ajax({
            type: "POST",
            url: "PullUserDb.php",
            data: { 'UsernameInput':UsernameInput },
            dataType: "text",
            success: function(data)
            {
            $('.body').html(data);
            }
        });
    });

});

index.php HTML:

 <div class = "HeaderLogin">
        <form class="LoginForm">
            <div class="control-group">
                    <div class="controls">
                    <input style = "height: 30px" type="text" id="inputEmail" placeholder="Email">
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                <input style = "height: 30px" type="password" id="inputPassword" placeholder="Password">
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <button style = "width: 200px" type = "button" class="SubmitLogin">Sign in</button>
                </div>
            </div>
        </form>
    </div>

PullUserDb.php:

<?php
//Connect to the server
$db_server = mysql_connect('localhost','root','');
if(!$db_server) die("Unable to connect to MySQL: " . mysql_error());
?>

<?php
//Connect to the database
mysql_select_db('databases')
    or die("Unable to select database: " . mysql_error());
?>

<?php
$Input_Username = $_POST['UsernameInput'];
//Pull columns and store them into variables
$query_users = "Select *

                FROM users

                WHERE Username = '".$Input_Username."'";

$result_users = mysql_query($query_users);
if (!$result_users) die ("Database access failed: " . mysql_error());

while($row_user_fetch = mysql_fetch_array($result_users))
   {
        $Username = $row_users_fetch['Username'];
        $Password = $row_users_fetch['Password'];
        $Email = $row_users_fetch['Email'];
        echo $Email;
   }
?>

1 个答案:

答案 0 :(得分:0)

我想出来了!这个代码已被编辑,以显示其他人需要它!当您输入一个好的用户名时,下面的代码将回复相应用户的电子邮件给客户类别。