<!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; }
为什么没有效果呢?错在哪了?
田心枫
千秋此意