Ajax XHR返回500错误,但给出了正确的结果

I am getting a 500 error when running this Ajax XHR. I can see in the console that the php code is returning the correct response, but the response is not being fed back to the client-side XHR. Is there something I am missing that would be causing this 500 error? I'm new to PDO and have been using mysqli for some time now.

index.php

    $("#login-submit").click(function(){
            $("#login-form").trigger("submit");
    });
    $("#login-form").submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: "http://admin.cvlgbtapp.com/login.php",
            data: $("#login-form").serialize(),
            cache: true,
            success: function(data) 
            {
                alert(data);
                switch(data)
                    {
                        case "1":
                            alert("Admin login successful. Redirecting...");
                            window.location = "console.php";
                            break;
                        case "2":
                            alert("User not recognized as administrator. Redirecting...");
                            window.location = "index.php";
                            break;
                        case "3":
                            alert("Password does not match account records. Please try again.");
                            break;
                    }
            }
        });
    });

login.php

<?php
    session_start();
    header('content-type: text/html; charset=utf-8');
    header('Access-Control-Allow-Origin: *'); 

$servername = "localhost";
$username = "redphyre";
$password = "Qazplm10!";

$user = $_POST['username'];
$pass = md5($_POST['password']);

    try {
        $conn = new PDO("mysql:host=$servername;dbname=cvlgbtq", $username, $password);
        // set the PDO error mode to exception
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "SELECT * FROM admins WHERE BINARY username = '$user'";
        $result = $conn->query($sql);
        if ($result->fetchColumn() < 1) {
            echo "2";
        }
        else {
            foreach ($conn->query($sql) as $row) {
                if ($row['password'] == $pass) {
                    echo "1";
                }
                else { echo "3"; }
            } 
        }
    }
    catch(PDOException $e)
    {
        echo "Connection failed: " . $e->getMessage();
    }

//  class SessionManager
//  {
//     static function sessionStart($name, $limit = 0, $path = '/', $domain = null, $secure = null)
//     {
//        // Set the cookie name before we start.
//        session_name($name . '_Session');
//
//        // Set the domain to default to the current domain.
//        $domain = isset($domain) ? $domain : isset($_SERVER['SERVER_NAME']);
//
//        // Set the default secure value to whether the site is being accessed with SSL
//        $https = isset($secure) ? $secure : isset($_SERVER['HTTPS']);
//
//        // Set the cookie settings and start the session
//        session_set_cookie_params($limit, $path, $domain, $https, false);
//        session_start();
//     }
//  }
    $result->close();
    $conn->close();
?>
</div>