我尝试了很多事情,但没有一个成功。我试图在选择框(选择以提取资产中心数据)后更改评级选项。它获取 php 文件中的数据,但我不知道如何处理 html 文件中的数据。
数据 servername 联系人分类等级 Server1 Ray Production A Server2 Eric Non-Production B
--
-- 数据库:
ipreservation
--
-- 表的表结构
acdata
CREATE TABLE IF NOT EXISTS `acdata` ( `servername` varchar(25) NOT NULL, `contact` varchar(20) NOT NULL, `classification` varchar(15) NOT NULL, `rating` varchar(4) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- 为表转储数据
acdata
INSERT INTO `acdata` (`servername`, `contact`, `classification`,`rating`) VALUES ('Server1', 'Ray', 'Production', 'A'), ('Server2','Eric', 'Non-Production', 'B');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /; / !40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /; / !40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
servertest.html
<html>
<head>
<script>
function showServer(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;
}
}
var server = document.getElementById('existingserver').value;
xmlhttp.open("GET","servertest.php?q="+server,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<label>Existing Server</label><input type="text" name="existingserver" id="textfield" maxlength="15"/>
<input type="checkbox" onclick="showServer(this.value)" >Select to Pull Asset Center Data<br>
<br />
<br />
Rating
<select name="rating" id="rating">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
</form>
<br />
<div id="txtHint"><b>Server info will be listed here.</b></div>
</body>
</html>
服务器测试.php
$con = mysql_connect('localhost', 'assignip', 'assignip'); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("ipreservation", $con); $sql = "SELECT * FROM acdata WHERE servername = '".$q."'"; $result = mysql_query($sql); echo "服务器名联系人分类等级";mysql_close($con); ?>while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['servername'] . "</td>"; echo "<td>" . $row['contact']. "</td>"; echo "<td>" . $row['classification'] . "</td>"; echo "<td>" . $row['rating'] . "</td>"; echo "</tr>"; } echo "</table>";