尝试使用jquery和ajax填充下拉列表

这是我的代码: –

 $(document).ready(function(){ //#This script uses jquery and ajax it is used to set the values in $("#day").change(function(){ //# the time field whenever a day is selected. var day=$("#day").val(); var doctor=$("#doctor").val(); $.ajax({ type:"post", url:"time.php", data:"day="+day+"&doctor="+doctor, dataType : 'json', success:function(data){ var option = ''; $.each(data.d, function(index, value) { option += '' + value.res + ''; }); $('#timing').html(option); } }); }); });  

这是PHP脚本。

   

我希望在我的html页面上的select中插入时间值的选项看起来像这样: –

   

我的java脚本代码正在将值发布到php脚本,但代码仍然无效。 我看到的javascript中没有任何错误。 请帮助我

  var postUrl = "time.php"; $.ajax({ type: "POST", url: postUrl, data: {day: day,doctor: doctor}, dataType: "json", success: function (data) { $.each(data, function (key, value) { $('#timing').append(''); }); } }); 

希望对你有所帮助

  success:function(data){ var select= ''; $('#timing').html(select); } 

HTML:

 
  var day=$("#day option:selected").val(); var doctor=$("#doctor option:selected").val(); data:"{day:'"+day+"', doctor: '" + doctor + "'}" ,