简体   繁体   English

PHP返回空白负载

[英]PHP returns loads of blank spaces

i have a login script that uses AJAX, but i have a problem with the code that i cannot work out. 我有一个使用AJAX的登录脚本,但是我的代码存在问题,无法解决。

Here is the code: 这是代码:

JS: JS:

$(document).ready(function(){
        $("#loginForm").submit(function(){

            $("#report").removeClass().addClass('loader').html('Loading...').fadeIn(1000);

            $.post("check_login.php",{ username:$('#signin_username').val(),password:$('#signin_pwd').val()},function(data){
                console.log(data);
                if(data == "TRUE"){
                    document.write(data);
                    console.log("YEP");
                    $("#report").fadeTo(200,1,function(){            
                        $(this).html('Logging in.....').addClass('log').fadeTo(900,1,function(){                 
                            document.location='members/index.php';
                        });           
                    });
                }
                else if(data == "FALSE"){
                    console.log("NOPE")
                    $("#report").fadeTo(200,1,function(){             
                        $(this).html('Username or password error.').addClass('error').fadeTo(900,1);
                    });     
                }
            });
            return false; 
        });

        $("#password").blur(function(){
            $("#login_form").trigger('submit');
        });
});

FORM: 形成:

<div id="login_form">
            <h3>Login</h3>
            <div id="signup_link">
                <a href="signup/">Signup Now</a>
            </div>
            <div id="report"></div>
            <form action="" method="post" id="loginForm">
                <ul>
                    <li>
                        <label for="username">Email: </label>
                        <input type="text" id="signin_username" name="signin_username" required="required" />
                    </li>
                    <li>
                        <label for="pwd">Password: </label>
                        <input type="password" id ="signin_pwd" name="signin_pwd" required="required" />
                    </li>
                    <li>
                        <input type="submit" name="login" id="login" value="Login"/>
                    </li>
                    <li><a href="members/forgotPass.php" class="forgot_pass">Forgot Password</a></li>
                </ul>
            </form>
        </div>

and PHP file called by js: 和js调用的PHP文件:

require_once 'members/classes/Membership.php';

# Make instance of membership class
$membership = new Membership();

$true = "FALSE";
$false = "FALSE";

if(!empty($_POST))
{       
    $username   = $_POST['username'];
    $pwd        = $_POST['password'];

    if($test = $membership->validate_user($username, $pwd))
        echo $true;
    else 
        echo $false;
}
else 
{
    echo "Details werent entered";  
}

Basically the method the php script is calling checks the database to see if the users details match and if they're allowed to login, if so returns true if not returns false (These are the only two values it will return. 基本上,php脚本调用的方法将检查数据库,以查看用户详细信息是否匹配以及是否允许他们登录,如果是,则返回true,否则返回false(这是将返回的仅有两个值)。

So it works file until we get back into the js code, note the first "console.log" the output of this seems to have loads of white space before the word that im looking for something like this: 因此它可以正常工作,直到我们回到js代码为止,注意第一个“ console.log”,其输出似乎在我正在寻找这样的单词之前包含大量空格:

"

TRUE" 真正”

The space above the true is nothing so when i test if(data == "TRUE") it's never true. 真实上方的空间什么都不是,所以当我测试if(data == "TRUE")它永远不会真实。

Either something strange is happening or i'm missing something really silly. 要么正在发生一些奇怪的事情,要么我真的错过了一些愚蠢的事情。 Can anyone see whats wrong? 谁能看到什么错?

Thanks for the time. 感谢您的时间。

Make sure you haven't got any include files that are outputting whitespace. 确保您没有任何包含空格的包含文件。 It's easy to make that mistake. 犯这个错误很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM