我想,當對應於下降的值向下選擇從數據庫提取數據,現在我得到一個錯誤:
TypeError: $(...).on is not a function
$("#country").on("change", function() {
我的代碼:
<htm>
<head>
<script src="js/jquery 1.7.js"></script>
<script>
$(function() { // document.ready
$("#country").on("change", function() {
$.ajax({
url: "country.php",
type: "POST",
data: {
country: $(this).val()
},
success: function(data) {
$("#results").html(data);
}
});
});
});
</script>
</head>
<body>
<div>
<form name="welcomeDiv1" id="welcomeDiv1">
<tr class="unsortable" >
<select name="country" id="country" >
<option value="">Select Country</option>
<?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = 'root';
$dbPassword = '';
$dbDatabase = 'priceflag';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");
$sql=mysql_query("SELECT DISTINCT `country` FROM 9xx");
while($row=mysql_fetch_assoc($sql))
{
print' <option id="country" name="country" value="'.$row['country'].'" >'.$row['country'].' </option>';
}
?>
</select>
</tr>
</form>
</div>
<div id="results"></div>
</body>
</html>
任何人都可以指導我如何解決這個錯誤
js沒有包含正確的請檢查你有沒有包含jquery庫一次這個頁面或嘗試使用jQuery –
爲什麼jQuery 3個版本? – Ramesh
你有沒有路徑中的3個jQuery文件? –