国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

javascript – Geben Sie eine ID ein, um verwandte Informationen abzufragen, es wird jedoch ?undefiniert' angezeigt
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-06-30 09:55:16
0
3
1000

Informationen k?nnen auf der PHP-Seite abgefragt werden, aber undefiniert wird auf der Frontend-Seite angezeigt

<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
</head>
<body>
    <p>
        <input type="text" name="idNum" id="idNum">
        <input type="button" value="查詢" id="btnSearch">
        <ul></ul>
    </p>
    <p id="myp"></p>

    <script type="text/javascript">
        $(function(){
            $("#btnSearch").bind("click",function(){
                //ajax
                $.post(
                    "search.php",
                    {num:$("#idNum").val()},
                    function (data) {
                        console.log(data);
                        $("ul").append(
                            "<li>mac:"+data.mac+"</li>"+"<li>name:"+data.name+"</li>"+"<li>password:"+data.password+"</li>"
                            );
                    }
                );
            })
        });

    </script>
</body>
</html>

Der PHP-Code lautet wie folgt



<?php
header("Content-type:text/json;charset=utf-8");
$num = filter_input(INPUT_GET, 'num', FILTER_SANITIZE_STRING);
//$num=$_GET["num"];
class p_mysqli extends mysqli {
    public function __construct($host, $user, $pass, $db) {
        parent::__construct($host, $user, $pass, $db);
        if (mysqli_connect_error()) {
            die('連接數(shù)據(jù)庫發(fā)生錯誤咯: (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
        }
    }
}

$mysqli=new mysqli('127.0.0.1', 'root', 'wl123456','proxys');
if ($mysqli->connect_errno) {
    die('Connect Error:'.$mysqli->connect_error);
}
$mysqli->set_charset('utf8');
$sql = "SELECT id,mac,name,password FROM s_user  WHERE id = ?";
//$sql = "SELECT mac,name,password FROM s_user  WHERE id = '207545'";
// 獲取預處理
$stmt = $mysqli->prepare($sql);
// 綁定參數(shù)
$stmt->bind_param("s", $num);
// 執(zhí)行
$stmt->execute();
// 獲取結果集
$result = $stmt->get_result();
// 獲取數(shù)據(jù)
$data = $result->fetch_all(MYSQLI_ASSOC);
echo json_encode($data);
?>

console.log(data) hat festgestellt, dass das Array leer ist

Die HTML-Seite zeigt das Ergebnis wie folgt an: mac:undefiniert

PHP中文網(wǎng)
PHP中文網(wǎng)

認證0級講師

Antworte allen(3)
某草草

感覺像是請求沒有返回數(shù)據(jù)。用瀏覽器調試工具看下請求的返回值

typecho

你把問題都說出來了啊,后臺返回的數(shù)據(jù)為空,判斷下數(shù)據(jù),空的時候就不走下面的邏輯!你在js里又使用了不存在的鍵值mac,肯定是undefined

曾經(jīng)蠟筆沒有小新

在PHP頁面最后echo之前打印變量data看有沒有值,如果沒有值 再在上面打印result的值就這樣一步一步定位問題

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage