1

我在让搜索功能使用 ajax 在用户输入名称时显示结果时遇到了一些麻烦。这是有问题的网站(您可以单击查看全部以查看可搜索的内容) http://ra-yon.com/beta/Test_sites/HFE/admin/contact.php正在 执行的查询 http://ra-yon .com/beta/Test_sites/HFE/include/queryc.php?query=ra-yon&clause=email

有问题的代码

<html>
    <head>

<style type="text/css">
body
{
background:black;
color:black;
width:100%;

}
#center
{
width:90%;
height:110%;
background:white;
margin:0 auto;
text-align:center;
color:black;
}
#insert{
background:navy; color:white; font-family:impact; font-size:18px;width:170px; height:170px; border-radius:50%;
margin:0 auto;
float: left; margin-left: 100px;
top:200px;
position: relative;
}
#insert:hover

{
background:white;
color:navy;
}
label
{width:150px;}
td
{
    border:solid 2px black;
    max-width: 250px;
    text-align: center;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">


function sendPHP(){

$('#table,#table2').css('display','none');
var query     = $('#searchname').attr('value');
var clause     = $('#searchclause').attr('value');
$.ajax({
    url: '../include/queryc.php?,
    type: 'POST',
  data: "query="+query+"&clause="+clause,
    dataType: 'html',
    success:
    function(data) {
        $(data).appendTo('#table');
    }
});
return false;
}



</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script></head>

<body>
   <a href="index.php"> <h4 style="float:right; color:blue; position: relative; left:-100px;" id="goback"> Go back? </h4></a>
    <div id="center">
<div id="queryform1" >
    <a href="#" onclick="$('#table2').css('display','block');">View All?</a>
    <span style="color:black;">search</span> <input type='text' onKeyUp="sendPHP();" name='searchname' id="searchname" />

<span style="color:black;">search by</span> <select name="searchclause" id="searchclause">
    <option value="name">Name</option>
    <option value="email">Email Address</option>
    <option value="subject">Subject</option>
    <option value="date">Date</option>

</select>
<a href="../include/downloadcontact.php">Download file?</a>

<div id="table2" style="display: none; margin: 0 auto; position: relative; top:40px; max-width:700px;">
    <div id="viewall">
        <?php
        include '../include/include.php';
        $sql = 'select * from contactus' ;



//print_r($sql);
$result=mysql_query($sql);

        ?>
        <table>
<tbody>
<th>Name</th><th>Email</th><th>Subject</th><th style="width:200px;">Message</th><th>Date</th>
<tr>
<?php
while ($client = mysql_fetch_array($result, MYSQL_ASSOC)){
echo "
<tr>

<td >".$client[name]."</td>
<td >".$client[email]."</td>
<td >".$client[subject]."</td>
<td >".$client[message]."</td>
<td >".$client[date]."</td>




</tr>";
} ?>
</tbody></table>
</div></div><div id="table">TestTestTest</div>


</div></div>

</body>
</html>

现在有点乱,我打算等我用完后清理一下。非常感谢大家!

4

1 回答 1

2

在控制台中检查了您的代码。你的功能失败了。您在这里缺少单引号:

    url: '../include/queryc.php?',

我使用 Google Chrome 的控制台以及在 Mozilla Firefox 的 Firbug 扩展中找到的控制台。他们在帮助解决小问题方面都非常宝贵

于 2013-03-19T14:05:59.427 回答