我这里有下拉和组合框。我试图使用ajax发布值。如果我创建另一个下拉列表,但是当我更改并在组合框中连接它时,我的ajax可以工作,ajax无效。
为什么ajax不起作用?请帮忙
我在dhtmlxcombo.js中的控制台中也出现错误:11它说TypeError:是空的
这是第11行
"keydown",function(a){try{(a||event).keyCode==9&&window.dhx_glbSelectAr[0].closeAll()}catch(b){}return!0});if(a.tagName=="SELECT")return dhtmlXComboFromSelect(a);else this._createSelf(a,b,c,d);dhx_glbSelectAr.push(this)}dhtmlXCombo.prototype.setSize=function(a){this.DOMlist.style.width=a+"px";if(this.DOMlistF)this.DOMlistF.style.width=a+"px";this.DOMelem.style.width=a+"px";this.DOMelem_input.style.width=Math.max(0,a-19)+"px"};
Ajax.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<script>
window.dhx_globalImgPath = "combobox/imgs/";
</script>
<link rel="STYLESHEET" type="text/css" href="combobox/dhtmlxcombo.css">
<script src="combobox/dhtmlxcommon.js"></script>
<script src="combobox/dhtmlxcombo.js"></script>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
Drop1
<?php
$combo = $mysqli->query("SELECT * FROM category GROUP BY cat_code ORDER BY id");
$option = '';
while($row = $combo->fetch_assoc())
{
$option .= '<option value = "'.$row['cat_code'].'">'.$row['category'].'</option>';
}
?>
<select id="main" name="main">
<option value="" disabled="disabled" selected="selected">Choose</option>
<?php echo $option; ?>
</select>
<select style='width:200px;' id="combo_zone1" name="alfa1">
<option value="">Select</option>
</select>
<div id="combo_zone2" style="width:200px; height:30px;"></div>
<input type="submit" name="submit" value="Submit"/>
<script>
var z = dhtmlXComboFromSelect("combo_zone1");
var z = new dhtmlXCombo("combo_zone2", "alfa2", 200);
z.readonly(1);
</script>
<script type="text/javascript">
$('#main').change(function(){
$.ajax({
url : 'getajax.php',
data :{mainlist_id : $(this).val()},
dataType:'html',
type:'POST',
success:function(data){
$('#combo_zone1').html(data);
}
});
});
</script>
</body>
</html>
Getajax.php
<?php
if (isset($_POST["mainlist_id"])) {
$mysqli = new mysqli("localhost", "root", "", "2015");
$main = $mysqli->real_escape_string($_POST["mainlist_id"]);
$result1 = $mysqli->query("SELECT * FROM code WHERE cat_code='$main' GROUP BY item_code ORDER BY item");
while($row = $result1->fetch_assoc())
{
?>
<option value ="<?php echo $row['item_code'];?>"><?php echo $row['item'];?></option>';
<?php
}
}
?>