我正在使用这个完全相同的教程http://www.w3schools.com/php/php_ajax_database.asp
创建了 2 个文件,一个 HTML 文件和一个 PHP(Conn/Query 等),它工作得很好,但唯一的问题是表格似乎失去了它的 CSS 格式。
任何想法为什么?谢谢
PHP文件
echo "<div class='widget'>
<div class='whead'><h6>Search Result</h6><div class='clear'></div></div>
<div id='dyn' class='hiddenpars'>
<a class='tOptions' title='Options'><img src='assests/images/icons/options' alt='Filter' /></a>
<table cellpadding='0' cellspacing='0' border='0' class='dTable' id='dynamic'>
<thead>
<tr>
<th>Name</th>
<th>Family</th>
<th>Age</th>
<th>Gender</th>
<th>Location</th>
</tr>
</thead>
<tbody>";
if ( count($result) ) {
foreach($result as $row) {
echo "<tr>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Family'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "<td>" . $row['gender'] . "</td>";
echo "<td>" . $row['Location'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
至于HTML 文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum- scale=1.0, user-scalable=0" />
<title>Test</title>
<link href="assests/css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="assests/js/plugins/forms/ui.spinner.js"></script>
<script type="text/javascript" src="assests/js/plugins/forms/jquery.mousewheel.js"> </script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" src="assests/js/plugins/tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="assests/js/plugins/tables/jquery.sortable.js"> </script>
<script type="text/javascript" src="assests/js/plugins/tables/jquery.resizable.js"></script>
<script>
function showName(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getName.php?q="+str,true);
xmlhttp.send();
}</script>
</head>
<body>
<div id="txtHint">
</div>
</body>
</html>