级联下拉列表无法使用JS工作

我有一个PHP和JS文件。 在这个文件中我有3个下拉菜单,我试图应用级联,但它不起作用。 当我在第一个下拉列表中选择一个选项时,第二个下拉列表没有任何值。

如何解决这个问题?

用于下拉列表的PHP:


Select by Position position) echo 'position .'">'. $option->position .''; else echo 'position .'">'. $option->position .''; }; ?>

Select by Location hiring_location) echo 'hiring_location .'">'. $option->hiring_location .''; else echo 'hiring_location.'">'. $option->hiring_location .''; }; ?>

Select by Processed processed_option) echo 'processed_option .'">'. $option->processed_option .''; else echo 'processed_option.'">'. $option->processed_option .''; }; ?>

JS:

  jQuery("#filterbyposition").live('change',function() { var selectVal = jQuery('#filterbyposition :selected').val(); alert(selectVal); var $output = jQuery('#filterbylocation').html(''); jQuery.ajax({ url: 'page-resume-databank.php', data: "n="+selectVal, dataType: 'json', success: function(data){ jQuery.each(data, function(key,value){ $output.append(""+value.filterbylocation+""); }); } }); }); 

你的代码错了

 jQuery("#filterbyposition").live('change',function() { var selectVal = jQuery('#filterbyposition :selected').val(); alert(selectVal); *var $output = jQuery('#filterbylocation').html('');* 

你为filterbyposition添加事件,代码jQuery(’#filterbylocation’)。html(”)设置为第二个下拉列表没有值。

将其更改为jQuery(’#filterbyposition’)。html(”)

在page-resume-databank.php中以selectforms回显输出,然后ajax中的响应只是附加第二个下拉列表。 ajax之后不需要.eachfunction

ajax请求

 var strURL="findStateing.php?platform="+xx; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('statediv').innerHTML=req.responseText; } else { alert("Problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } 

findStateing.php如下所示重新响应

  $xx=$_GET['platform'];