Post方法不向php页面发送数据

I used post method to send data (username and password ) from xdk app to php file by XMLHttpRequest object,but i faced a problem. all data i sent by post method undefined in php file.

this xdk code

<!DOCTYPE html>
<html lang="en-US">
<head>
    <script type="text/javascript">
        function login() {
            var xhr = new XMLHttpRequest();
            var username1 = document.getElementById("user_name").value;
            var pass = document.getElementById("pass_word").value;
            var params = "username=" + username1 + "&password=" + pass;
            alert(params);
            xhr.open("post", "http://localhost/hospital/test.php", false);
            xhr.onload = function () {
                if (xhr.status == 200) {
                    var json_string = xhr.responseText;
                    test.innerHTML = json_string;
                }
                else if (xhr.status == 404) {
                    alert("Web Service Doesn't Exist", "Error");
                }
                else {
                    alert("Unknown error occured while connecting to server", "Error");
                }
            }
            xhr.send(params);
        }
    </script>
</head>
<body>
<div class="container">
    <div id="login">
        <img src="img/logo.png" width="100 px" height="100 px"/>
        <form onsubmit="login(); return false;">
            <fieldset class="clearfix">
                <p><span class="fontawesome-user"></span><input type="text" id="user_name"/></p>
                <p><span class="fontawesome-lock"></span><input type="password" id="pass_word"/></p>
                <p><input type="submit" value="تسجيل الدخول"/></p>
            </fieldset>
        </form>
        <div id="test"></div>
</body>
</html>

this is php code

<?php
$con = mysqli_connect("localhost", "root", "", "interactive");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_POST["username"])) {
    $username = $_POST["username"];
    $password = $_POST["password"];
}

$sql = "SELECT * FROM Caregiver WHERE UserName = $username && password =     $password ";
$result = mysqli_query($con, $sql);
$num = $result->num_rows;
if ($num) {
    $row = $result->fetch_array(MYSQLI_BOTH);
    $data = array('status' => 'success', 'username' => $row['UserName'], 'password' => $row['password']);
} else {
    $data = array('status' => 'failure', 'Error: ' . mysqli_error($con));
}
echo json_encode($data);
mysqli_close($con);
?>

this is a little outside my wheelhouse, but i think you probably need a port here:

xhr.open("post", "http://localhost/hospital/test.php", false);

like

xhr.open("post", "http://localhost:port/hospital/test.php", false);