2014-10-08 65 views
-5

我在地图上添加了一个搜索栏,它工作正常,但是当我开始会话时,发生了一些事情,突然它停止工作。当我删除会话,它的工作原理,但会议它不起作用。 有人吗?搜索栏不工作后session_start()

我的PHP代码

<?php session_start(); 
    if(isset($_SESSION['username']) && $_SESSION['username']!="") 
    { 
?> 
     <input type="text" value="" id="searchbox"> 
<?php 
    } 
    else 
    { 
    //echo "You are not supposed to be here. Please <a href='login.php'>login</a> first."; 
    header("Location:login.php"); 
    } 
?> 

代码:

$(function() { 
    $("#searchbox").autocomplete({ 
     source: function(request, response) { 
      if (geocoder == null) { 
       geocoder = new google.maps.Geocoder(); 
      } 
      geocoder.geocode({ 
       'address': request.term 
      }, function(results, status) { 
       if (status == google.maps.GeocoderStatus.OK) { 
        var searchLoc = results[0].geometry.location; 
        var lat = results[0].geometry.location.lat(); 
        var lng = results[0].geometry.location.lng(); 
        var latlng = new google.maps.LatLng(lat, lng); 
        var bounds = results[0].geometry.bounds; 
        geocoder.geocode({ 
         'latLng': latlng 
        }, function(results1, status1) { 
         if (status1 == google.maps.GeocoderStatus.OK) { 
          if (results1[1]) { 
           response($.map(results1, function(loc) { 
            return { 
             label: loc.formatted_address, 
             value: loc.formatted_address, 
             bounds: loc.geometry.bounds 
            } 
           })); 
          } 
         } 
        }); 
       } 
      }); 
     }, 
     select: function(event, ui) { 
      var pos = ui.item.position; 
      var lct = ui.item.locType; 
      var bounds = ui.item.bounds; 
      if (bounds) { 
       map.fitBounds(bounds); 
      } 
     } 
    }); 
}); 
+0

看看html页面的来源。它看起来像PHP生成一个错误'头被以前发送......'这使您的HTML代码无效。 – Cheery 2014-10-08 04:56:53

+0

这是html代码: -
2014-10-08 05:06:45

+0

伙计,PHP代码导致错误,你给我们HTML :) – 2014-10-08 05:07:46

回答

1

我还没有看到你的代码,但我要去无路可退,并说,这是最有可能是因为你没有将session_start()放在页面的最顶端。如果在调用session_start()函数之前有ANY空格,PHP将会引发错误。

+0

我已经删除所有的空格,但仍然无法正常工作 – 2014-10-08 05:16:58