2016-11-29 8 views
-1

私は2つのページ(html & js)を持っていますが、データはajax(データベースから)から返され、空間クエリを作成しました。リストボックス)がhtmlページにありますが、それは動作していません(データはリストボックスにロードされていません)。 これは、HTMLの一部です:htmlにデータをロードしても動作しません

<div> 
<select name="FarmersID" id="FarmersID" multiple style="width:172px"> 
</select> 
</div> 

、これは、Ajax一部です

$.ajax({ 
     type:"POST", 
     url:"CustomerID_geojson.php", 
     data:{'OrdersID': Order_ID} , 
     dataType: 'json', 
     success: function (response) { 
      var unit = 'kilometers'; 
      var buffered = turf.buffer(response, distance, unit); 
      bufresult = buffered.geometry.coordinates; 
      $.ajax({ 
       type: "POST", 
       url: 'allfarmers_geojson.php', 
       dataType: 'json', 
       success: function (data) 
       { 
        var searchWithin = { 
         "type": "FeatureCollection", 
         "features": [ 
         { 
          "type": "Feature", 
          "properties": {}, 
          "geometry": { 
          "type": "Polygon", 
          "coordinates": bufresult 
          } 
         } 
         ] 
        }; 

        var ptsWithin = turf.within(data,searchWithin); 
        //to check if there are any farmers within the distance or not 
        if (ptsWithin.features.length > 0) 
        { 
         geojsonLayer = L.geoJson(ptsWithin, 
          { 
           onEachFeature: function (feature, layer) 
           { 
            FarmerID=feature.properties.Farm_id; 
            document.getElementById('FarmersID').value=FarmerID; ///This one is not working 
            layer.bindPopup('<label>Farmer Name:</label>' + feature.properties.nick_name_ + '<br><label>Farmer ID:</label>' + feature.properties.Farm_id); 
           } 
          }).addTo(mymap); 
         mymap.fitBounds(geojsonLayer.getBounds()); 

        } 
        else 
        { 
         alert("No Farmers Found!"); 
        } 
       } 
      }); 

     } 
    }); 
+0

@Dylan Hamilton ...これを確認できますか? – Beginner

答えて

1
$('#FarmersID').append($('<option>', { 
    value: 1, 
    text: 'My option' 
})); 

reffer this anwer

私は、これはuはあなたの選択にオプションを追加やりたいことを望みますアイテムをajaxレスポンスで返します。

+0

ありがとうございました:)...それは動作します...しかし、値の "1"は何を参照することができますか? – Beginner

+0

値1は、上記のスクリプトを追加するオプション要素の値です。** **を選択要素に追加します。 uに必要な値を設定できます。 –

関連する問題