我能够将服务器名称传递给成功运行查询的 PHP。在 html 文件中,我希望根据 PHP 文件返回的值来更改评级选项。在我的文件中,我将其设置为 D,但我需要更改它以反映 PHP 返回的内容。
服务器.html
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
var id = $('#existingserver').val();
$('#assetCenter').click(function(){
var id = $('#textfield').val();
$.get('servertest.php',{q:id}, function(htmlData){
$('#txtHint').html(htmlData);
var rating = $(htmlData).find("td[data-col=rating]").text();
alert(rating);
});
});
});
</script>
</head>
<body>
<form>
<label>Existing Server</label><input type="text" name="existingserver" id="textfield" maxlength="15"/>
<input type="checkbox" id="assetCenter" >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
<?php
$q=$_GET["q"];
$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 "<table border='1'>
<tr>
<th>Servername</th>
<th>Contact</th>
<th>Classification</th>
<th>Rating</th>
</tr>";
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 "<td data-col='rating'>" . $row['rating'] . "</td>";
}
echo "</table>";
mysql_close($con);
?>
数据库字段:servername、contact、classification、rating 数据:Server1、Ray、Production、A