我發現這個使用PHP/MySQL/AJAX/jQuery的chained select box不能用jQuery1.9.1運行。第一個選擇框工作正常,但是當我選擇第二個,它使用type_list.php從sql檢索數據時,即使php文件被觸發,也無法提取任何數據。任何人都知道爲什麼它不適用於jQuery 1.9.1?爲什麼這個動態選擇框不適用於jQuery 1.9.1?
jQuery 1.9.1:Example - 無法正常工作。
jQuery 1.7.2:Example - 工作正常。
type_list.php:
<?php
// list of printer types for specific manufacturer
include("dbconfig.inc.php");
header("Content-type: text/xml");
$manid = $_POST['man'];
echo "<?xml version=\"1.0\" ?>\n";
echo "<printertypes>\n";
$select = "SELECT type_id, type_text FROM printer_types WHERE man_id = '".$manid."'";
try {
foreach($dbh->query($select) as $row) {
echo "<Printertype>\n\t<id>".$row['type_id']."</id>\n\t<name>".$row['type_text']."</name>\n</Printertype>\n";
}
}
catch(PDOException $e) {
echo $e->getMessage();
die();
}
echo "</printertypes>";
?>
JS代碼:
<script>
jQuery().ready(function($){
$('#loading')
.hide() // hide it initially
.ajaxStart(function() {
$(this).show();
})
.ajaxStop(function() {
$(this).hide();
})
;
// Ajax Called When Page is Load/Ready (Load Manufacturer)
jQuery.ajax({
url: 'man_list.php',
global: false,
type: "POST",
dataType: "xml",
async: false,
success: populateComp
});
//Ajax Called When You Change Manufaturer
$("#manufacturer").change(function()
{
resetValues();
var data = { man :$(this).attr('value') };
jQuery.ajax({
url: 'type_list.php',
type: "POST",
dataType: "xml",
data:data,
async: false,
success: populateType
});
});
//Ajax Called When You Change Type of Printer
$("#printertype").change(function()
{
var data = {
man :$('#manufacturer').val(),
typ : $(this).attr('value')
};
jQuery.ajax({
url: 'model_list.php',
type: "POST",
dataType: "xml",
data:data,
async: false,
success: populateModel
});
});
//Do What You Want With Result .......... :)
$("#printermodel").change(function()
{
//'you select Model='+$('#manufacturer').val()+'type='+$('#printertype').val()+'And Model='+$('#printermodel').val()
alert('you select Model = '+$('#manufacturer option:selected').text()+' ,type= '+$('#printertype option:selected').text()+' And Model = '+$('#printermodel option:selected').text()
);
});
});
</script>