<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Chatrobot</title>
</head>
<body>
    <input type="text">
    <input type="button" value='发送'>
    <script>
        var send = document.querySelector('input[type=button]')
        var text = document.querySelector('input[type=text]').value
        send.onclick = function() {
            //1.创建异步对象
            var xhr = new XMLHttpRequest()
                //2.设置请求行(get请求数据写在url后面)
            xhr.open('get', 'chat.php?text=' + text) //第三个参数默认为true(异步)
                //3.设置请求头(get可以省略,post不发送数据也可以省略)
            xhr.setRequestHeader('aays', 'aays666')
                //4.注册回调函数
            xhr.onload = function() {
                    console.log(xhr.responseText);
                }
                //5.发送请求主体
            xhr.send()
        }
    </script>
</body>
</html>
<?php
header("Content-type:text/html;charset=utf-8");
$chat=array('凡事问问自己配不配','小牛马','QWQ','德玛西亚');
$randnumber=array_rand($chat,1);
echo $chat[$randnumber];
?>