谷歌地图显示标记不工作时调用你下拉选择使用ajax


Google map show marker not working when called you dropdown select using ajax

我有一个联系人页面,他们在国家/地区有多个分支机构。因此,尝试过滤位置并在城市选择时,它应该显示带有信息窗口的标记。我的问题是,如果我直接选择城市,它是有效的,但当通过文件管理器下拉列表时,它不起作用。请告诉我我做错了什么。

这是我的链接http://www.safarikidindia.com/demo_map.html

这是我的代码

在乡村下拉列表中,我调用onchange="generatedestate(this)">&生成城市对州下拉列表。这是ajax函数代码

function generatestate(o)
 {
set_current_date_time()
http.abort();
document.getElementById('locationstate').innerHTML = '';
document.getElementById('locationcity').innerHTML = '';
var url = "common_ajax.php?action=showstate&countryid="+o.options[o.selectedIndex].value;
    //alert(url);
  http.open("GET", url, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
            //alert(http.responseText);
            //var response = http.responseText;
              document.getElementById('locationstate').innerHTML = http.responseText;
        //    alert(http.responseText);
    }
  }
  http.send(null);

 }

  function geneeratecity(o)
 {
set_current_date_time()
http.abort();
document.getElementById('locationcity').innerHTML = '';
var url = "common_ajax.php?action=geneeratecuty&stateid="+o.options[o.selectedIndex].value;
    //alert(url);
  http.open("GET", url, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
            //alert(http.responseText);
            //var response = http.responseText;
              document.getElementById('locationcity').innerHTML = http.responseText;
            //alert(http.responseText);
    }
  }
  http.send(null);

 }

 ////////////////////////////////

在common_ajax中,我们有以下php函数

      if($action=="showstate")
 {
$countryid = trim(filter_var($_REQUEST['countryid'], FILTER_SANITIZE_STRING));
$state = $safari->country_state_location($countryid);
?>
<select name="city" id="city" class="drpdown" onchange="geneeratecity(this);">
          <option value="">Select State</option>
          <?php 
          for($i=0;$i<count($state);$i++)
          {
          $statename = $safari->get_singlestate($state[$i]['state'])
          ?>
                 <option value="<?php echo $statename[0]['statesrno'];?>"><?php echo     $statename[0]['statename'];?></option>
          <?php
          }
          ?>

        </select>
<?php 
 }
 if($action=="geneeratecuty")
 {
$stateid = trim(filter_var($_REQUEST['stateid'], FILTER_SANITIZE_STRING));
$locations = $safari->country_city_location($stateid);
?>
        <select name="city" class="city" id="city">
          <option value="" selected>--- Select ---</option>
                       <?php 
        for($l=0;$l<count($locations);$l++)
        { ?>
        <option value="marker<?php echo $locations[$l]['srno'];?>"><?php echo $locations[$l]['city'];?></option>


        <?php } ?>
        </select>


     <?php 
 }
  ?>

更改侦听器绑定到调用initialize时存在的#city元素。当您筛选列表时,此元素将被覆盖,新创建的select将不会侦听侦听器。

可能有不同的方法来修复它,但您已经使用了jQuery,所以我建议使用jQuery的on()而不是google.maps.event.addDomListener:

jQuery(document).on('change','#city',
  function(){
    //your code
  }
);