Beginner Beginner - 8 months ago 66
Ajax Question

Loading data to html is not working

I have two pages (html & js),I have data returned from ajax (from database),i made spatial query on it and i want to load some of its data in an input (listbox) in html page but it is not working (no data is loaded in the listbox).
This is the part of html:

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

and this is the ajax part

data:{'OrdersID': Order_ID} ,
dataType: 'json',
success: function (response) {
var unit = 'kilometers';
var buffered = turf.buffer(response, distance, unit);
bufresult = buffered.geometry.coordinates;
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)
document.getElementById('FarmersID').value=FarmerID; ///This one is not working
layer.bindPopup('<label>Farmer Name:</label>' + + '<br><label>Farmer ID:</label>' +;

alert("No Farmers Found!");


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

reffer this anwer

I hope this is what u want to do add options to your select item via ajax response.