doutang7707 2013-08-17 07:46
浏览 18
已采纳

使用ajax调用drop down时,Google地图显示标记无法正常工作

I have a contact page where they have multiple branches in countries. So trying to filter the location and on city select it should show the marker with info window. My problem is if I select the city directly it works but when going thru the filer dropdown it doesnt work. Please advice on what am I doing wrong.

This is my link http://www.safarikidindia.com/demo_map.html

here is my code

On country drop down I call onchange='generatestate(this)'> & generate city on state drop down. here is the ajax function code

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);


 }



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

In common_ajax we have following php function

      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 

 }

  ?>
  • 写回答

1条回答 默认 最新

  • dragonsun2005 2013-08-17 09:15
    关注

    The change-listener is bound to the #city-element that exists when you call initialize. When you filter the lists, this element will be overwritten, the newly created select will not listen to the listener.

    There may be different ways to fix it, but you already use jQuery, so I would suggest to use jQuery's on() instead of google.maps.event.addDomListener :

    jQuery(document).on('change','#city',
      function(){
        //your code
      }
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度