0
我的選擇標籤會給我玩家的名字,然後Query會在後面運行,然後結果會顯示出來。我已經通過一些教程,但無法找到答案。我在這裏添加我的HTML和PHP文件代碼。JQuery和Ajax不起作用
//html and script player.html file
<script>
<script type="text/javascript" src="jque`enter code here`ry.js">
$(document).ready(function() {
$('#player').on('change', function() {
var qString = '{name: ' + $('#player option:selected').text() + '}';
$.post('getplayer.php', qString, processResponse);
// $('#resultsGoHere').html(qString);
});
function processResponse(data) {
$('#resultsGoHere').html(data);
}
});
</script>
<form id="myForm">
<select id="player" name="player" onchange="showPlayer(this.value)">
<option value = "None">Choose One</option>
<option value = "Zidane">Zidane</option>
<option value = "Messi">Messi</option>
<option value = "Cristiano Ronaldo">Cristiano Ronaldo</option>
<option value = "Bergkemp">Bergkemp</option>
</select></br></br>
<!--<input type="submit" name="submit" value="Submit" />-->
</form>
//php part getplayer.php file
<?php
$name = $_POST['theDropdown'];
echo "$name";
/*
$db = mysql_connect("localhost","root","root");
mysql_select_db("football");
$select = "SELECT * FROM players";
$result = mysql_query($select) or die(mysql_error());
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Position</th>
<th>Club</th>
<th>Nationality</th>
<th>Date of birth</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<th>" . $row['id'] . "</td>";
echo "<th>" . $row['name'] . "</td>";
echo "<th>" . $row['pos'] . "</td>";
echo "<th>" . $row['club'] . "</td>";
echo "<th>" . $row['nationality'] . "</td>";
echo "<th>" . $row['dob'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($db);
*/
?>
好,這看起來相當混亂給我,能否請您先解決您的HTML標記?從「
你可以做這樣的事情
所以在process.php頁
來源
2013-02-09 08:15:26 Roger