原生ajax啦啦啦

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div>请输入查询编号:<input type="text" id="put_info">
        <input type="button" id="btnSubmit" value="查询">
        <p id="content"></p>
    </div>


    <script>
        document.getElementById("btnSubmit").onclick = function () {
            search();
        };
        function search() {
            var request = new XMLHttpRequest();
            request.open('GET','raw_ajax_php.php?number=' + document.getElementById("put_info").value ,true);
            request.send();
            if (request.readyState === 4){
                if (request.status === 200){
                    document.getElementById("content").innerHTML = request.responseText;
                }else {
                    alert("请求发生错误!");
                }
            }
        }
    </script>
</body>
</html>
<?php
/**
 * Created by PhpStorm.
 * User: weiwei
 * Date: 2017/3/30
 * Time: 23:00
 */
header("content-type:text/html;charset=utf-8");

$numberinfo = array("jack","mary","oliao","griffin");

$number = $_GET["number"];

if (!isset($number) || empty($number)){
    echo "输入有误!";
}

switch ($number){
    case 1:
        echo $numberinfo['0'];
        break;
    case 2:
        echo $numberinfo[1];
        break;
    case 3:
        echo $numberinfo[2];
        break;
    case 4:
        echo $numberinfo[3];
        break;
}

为什么没有效果呢?错在哪了?

西兰花伟大炮
浏览 1369回答 3
3回答

田心枫

不会啊 原生的

千秋此意

function search() {     var request = new XMLHttpRequest();     request.open('GET', 'raw_ajax_php.php?number=' + document.getElementById("put_info").value, true);     request.send();     request.onreadystatechange = function() {         if (request.readyState === 4) {             if (request.status === 200) {                 document.getElementById("content").innerHTML = request.responseText;             } else {                 alert("请求发生错误!");             }         }     } }这样写就行了(大佬你最近疯狂提问是在攒积分吗=、=)
打开App,查看更多内容
随时随地看视频慕课网APP