Javascript PHP echo未在DIV中显示

Javascript PHP echo未在DIV中显示,javascript,php,html,Javascript,Php,Html,我有一个HTML页面,它将一个PHP文件加载到一个DIV中,如下所示: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Intranet</title> <link href="styles.css" rel="stylesheet" type="text/css"&g

我有一个HTML页面,它将一个PHP文件加载到一个DIV中,如下所示:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Intranet</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div>
    <nav>
        <ul>
           <li><a href="javascript:void()" onclick=$('#content').load('test.php'); return false">Employee Lookup</a></li>
        </ul>
    </nav>
 </div>
 <div class="content-center" id="content"></div>
</body>
</html>

内部网
DIV被命名为content

PHP文件在DIV中有一个搜索表单,PHP脚本执行数据库搜索,并将检索到的数据回送到同一页面上的DIV中。如果我不将PHP文件加载到主HTML页面上的DIV中,这就可以了。当我在DIV中加载PHP文件时,PHP文件中的表单会正确地显示在主页上的DIV中,但是搜索结果不会。它们根本不显示,DIV只显示原始HTML页面。不知道为什么会这样

以下是PHP文件的代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=11">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
<link href="styles.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/jquery.tools.min.js"></script>
<script src="http://code.jquery.com/jquery-git.js"></script>
<script type="text/javascript" src="js/HelperFunctions.js"></script>
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.-->
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/open-sans-condensed:n3:default.js" type="text/javascript"></script>
</head>
<body>
<div>
<h1 class="page-title">Employee Directory Lookup:</h1>
<form name="phonesearch" action="" method="GET" style="text-align: center">
Name <input type="text" id="user" name="user"> &nbsp;
Unit <input type="text" id="unit"> $nbsp;
Roles <input type="text" name="role"> &nbsp;
Number <input type="text" name="number" > &nbsp;
<input name="search" type="submit" value="Search">
</form>
</div>

<script type = "text/javascript">
    document.forms['phonesearch'].elements['user'].focus();
</script>

<script type="text/javascript">

$(document).ready(function()
{
  $("tr:even").css("background-color", "#D7D2C2");
  $("tr:odd").css("background-color", "#E6E6E6");
});
</script>
<div class="result">
<?php
 if(!empty(isset($_GET['search']))) {
    clearstatcache();
    $searchName = htmlspecialchars($_GET["user"]);
    $searchUnit = htmlspecialchars($_GET["unit"]);
    $searchRole = htmlspecialchars($_GET["role"]);
    $searchNum = htmlspecialchars($_GET["number"]);
    $username = "test";
    $password = "test";
    try {
        // Initiate database connection using PDO prepared statements.
        $db = new PDO("sqlsrv:Server=ServerName\DatabaseName;Database=001active",$username,$password);

        // Add wildcards to our search strings so that they are more searchable.
        $searchName = explode(' ',$searchName);
            $searchName1 = '%' . $searchName[0] . '%';
        if (count($searchName) > 1)
            $searchName2 = '%' . $searchName[1] . '%';
        else
            $searchName2 = '%%';
        $searchRole = '%' . $searchRole . '%';
        $searchNum = FormatNumber($searchNum);
        // The actual query we'll run. Don't worry about it...
        $sql = "SELECT PMMain.NAME_FULLB, PMMain.NAME_OTHER, PMMain.WORK_PHONE, PMMain.OTHER_PHONE,
            PMMain.CELLULAR, PMMain.STATUS_COMMENT, PMUser.USR_FIELD_11,
            PMUser.USR_FIELD_12, PMMain.NAME_FIRST, PMMain.NAME_LAST,
            PMMain.NAME_OTHER, PMMain.OTHER_CONTACT, PMUser.USR_MEMO_2, PMUser.USR_MEMO_1
            FROM PMUser INNER JOIN PMMain ON PMUser.ID = PMMain.ID
            WHERE PMMain.NAME_FULLB NOT LIKE ',%' AND PMMain.COMPANY_CODE = 'ACTIVE' AND
            (PMMain.NAME_FULLB LIKE :search_user OR PMMain.NAME_OTHER LIKE :search_user2
            OR PMMain.NAME_FULL LIKE :search_user3) AND
            (PMMain.NAME_FULLB LIKE :search2_user OR PMMain.NAME_OTHER LIKE :search2_user2
            OR PMMain.NAME_FULL LIKE :search2_user3) AND
            (PMUser.USR_MEMO_2 LIKE :search_role OR PMUser.USR_MEMO_2 IS NULL) AND PMUser.USR_FIELD_11 LIKE :search_Unit
            ORDER BY PMMain.NAME_LAST ASC";
            // Prepare the query!
            $statement = $db->prepare($sql);
            // Assign the variables in the SQL query to our 'get' variables.
        $statement->bindParam(':search_user', $searchName1, PDO::PARAM_STR);
        $statement->bindParam(':search_user2', $searchName1, PDO::PARAM_STR);
        $statement->bindParam(':search_user3', $searchName1, PDO::PARAM_STR);
        $statement->bindParam(':search2_user', $searchName2, PDO::PARAM_STR);
        $statement->bindParam(':search2_user2', $searchName2, PDO::PARAM_STR);
        $statement->bindParam(':search2_user3', $searchName2, PDO::PARAM_STR);
        $statement->bindParam(':search_role', $searchRole, PDO::PARAM_STR);
        $statement->bindParam(':search_Unit', $searchUnit, PDO::PARAM_STR);
        // Run the query!
        $statement->execute();
        // Return the data
        if ($data = $statement->fetchAll()){
            // Table headers
            echo '<table align="center" padding-right="15px"><tr><tr><th>Unit</th><th>Last Name</th><th>First Name</th><th>Other Name</th>
            <th>Roles</th><th>Work Phone</th><th>Direct Phone</th><th>Cell Phone</th>
            <th>Supervisor</th><th>Location</th></tr>';
            // This var is just to count the lines returned.
            $index = 0;
            // Format all our results into our pretty table.
            foreach($data as $row)
            {
                if($searchRole != '%%' && $row['USR_MEMO_2'] == '')
                    continue;

                // Here we filter out numbers not matching our number search post-query.
                if($searchNum != '')
                    if (!((LikeMatch($searchNum,FormatNumber($row['WORK_PHONE'])))
                        || (LikeMatch($searchNum,FormatNumber($row['CELLULAR'])))
                        || (LikeMatch($searchNum,FormatNumber($row['OTHER_PHONE'])))))
                        continue;
                $index++;
                echo '<br/><br/>';
                echo '<tr><td>' .$row['USR_FIELD_11'] . '</td><td>' . $row['NAME_LAST']
                . '</td><td>';
                // if ($row['NAME_OTHER'] != null)
                //  echo $row['NAME_OTHER'];
                // else
                    echo $row['NAME_FIRST'];
                    echo '</td><td class="cell">'. $row['NAME_OTHER']. '</td><td class="cell">' . $row['USR_MEMO_2'] . '</td><td class="phone">' . FormatPhone($row['WORK_PHONE'])
                . '</td><td class="phone">' .   FormatPhone($row['OTHER_PHONE']) . '</td><td class="phone">' . FormatPhone($row['CELLULAR'])
                . '</td><td>' . $row['OTHER_CONTACT'] . '</td><td>' . $row['USR_FIELD_12'] . '</td></tr>';
            }

            echo '</table>';
        }
        else {
            echo '<b>No results found.</b>';
        }

        // disconnect
        $db = null;
    }
        catch(PDOException $e) {
            echo $e->getMessage();
    }
 }
function FormatNumber ($input)
{
    // Removes special characters from a phone number for comparison testing/searching
    return preg_replace('/[^0-9,]|,[0-9]*$/','',$input);
}
function FormatPhone ($input)
{
    //return preg_replace('~.*(\d{3})[^\d]*(\d{3})[^\d]*(\d{4}).*~', '($1) $2-$3', $input);
    // no area code:
    return preg_replace('~.*(\d{3})[^\d]*(\d{3})[^\d]*(\d{4}).*~', '$2-$3', $input);
}
function LikeMatch($input, $base)
{
    // Used for searching if a string is contained in another string.
    if(strpos($base, $input)) {
        return true;
    }
    else {
        return false;
    }
}
?>
</div>
</body>
</html>

var\uuuu adobebfontsappname=“dreamweaver”
员工目录查找:
名称
单位:$nbsp;
角色
数
document.forms['phonesearch'].elements['user'].focus();
$(文档).ready(函数()
{
$(“tr:偶数”).css(“背景色”,“#D7D2C2”);
$(“tr:odd”).css(“背景色”,“#e6”);
});

我在这段代码中看不到任何
回音
。我没有发布所有代码。echo语句在PHP代码中的位置更靠下。正如我所说,如果我只运行PHP文件,它就可以正常工作。如果我将其加载到主HTML页面的DIV中,则只加载PHP文件中的表单,当我进行搜索时,不会看到结果。我希望结果显示在PHP加载到我的HTML主页上的同一个DIV中。这不是因为您有一个
if
语句,该语句可能返回false吗?如果您可以使用产生问题所需的最小代码量创建一个,我们可以查看发生了什么,以找到问题所在。例如,您包含了与问题无关的信息,例如
标题和
选择中的所有选项(只有两个选项可以,除非这也是问题所在),但是您没有向我们显示带有
回音的代码,这实际上与问题有关:)我用一个html文件和php文件的示例编辑了原始文件。