Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 选择的selectbox刷新一步太晚_Jquery - Fatal编程技术网

Jquery 选择的selectbox刷新一步太晚

Jquery 选择的selectbox刷新一步太晚,jquery,Jquery,在互联网的大量帮助下,我制作了一个脚本,根据用户在selectbox1中选择的内容刷新selectbox2。问题是selectbox2太迟了一步 我会尝试解释: 当我选择伦敦时,我想在selectbox2中看到伦敦的所有学校,但selectbox2没有任何效果。然后我选择曼彻斯特,然后选择框2显示伦敦的所有学校 function fetch_select(val) { $.ajax({ type: 'post', url: 'test_fetch_data.php',

在互联网的大量帮助下,我制作了一个脚本,根据用户在selectbox1中选择的内容刷新selectbox2。问题是selectbox2太迟了一步

我会尝试解释: 当我选择伦敦时,我想在selectbox2中看到伦敦的所有学校,但selectbox2没有任何效果。然后我选择曼彻斯特,然后选择框2显示伦敦的所有学校

function fetch_select(val)
{
   $.ajax({
     type: 'post',
     url: 'test_fetch_data.php',
     data: {
       get_option:val
     },
     success: function (response) {
       document.getElementById("wijk").innerHTML=response; 
     }


   }
   );

$(".chosen-select").chosen().change( function() {
  var selectedValue = $(this).find('option:selected').val();
    console.log(selectedValue);
  $(".chosen-select").find('option[value="'+ selectedValue +'"]:not(:selected)').attr('disabled','disabled');
  $(".chosen-select").trigger("chosen:updated");
});

}
如果我不使用所选的类,一切都正常,所以我想问题不在javascript中

提前谢谢

test_fetch_data.php:

   if(isset($_POST['get_option']))
{

 $state = $_POST['get_option'];
 $find=mysql_query("select wijk from geografie_wijken where plaats='$state'");
 while($row=mysql_fetch_array($find))
 {
   echo "<option>".$row['wijk']."</option>";
 }

 exit;
  }
选择部分:

<select class="chosen-select chosen-select-deselect" name="plaats" id="plaats" onChange="fetch_select(this.value);">  
     <option value=""></option>  


         $select=mysql_query("select DISTINCT(plaats) from geografie_wijken");
         while($row=mysql_fetch_array($select))
         {
          echo "<option>".$row['plaats']."</option>";
         }


     </select>

  <select name="wijk" id="wijk" data-placeholder="Selecteer uw keuze(s)..."  multiple="multiple" class="chosen-select">

UPD。在我看来,问题似乎是由于这个代码

$(".chosen-select").trigger("chosen:updated");

在异步ajax回调之前被调用。在重新分配带有响应的selectbox的innerHTML后,尝试将其放入成功函数中。

能否提供您使用的代码?例如,如何触发fetch_select?另外,PLZHTML的选择。嗨,我已经添加了其他代码@Wouter怎么不工作:根本不工作还是很晚才恢复?