I want to fetch all the layer names from GeoServer using AJAX and append the data in the HTML dropdown. I used xampp server and file in .php extension, Here is my code :
HTML code :
<label for="layer">Select Layer</label>
<select class="form-control" id="layer" name="layer">
<option value="">Select Layer</option>
</select>
Jquery code :
$(document).ready(function(){
$.ajax({
type: "GET",
url: "http://localhost:8080/geoserver/wfs?request=getCapabilities",
dataType: "xml",
success: function(xml) {
var select = $('#layer');
$(xml).find('FeatureType').each(function(){
var name = $(this).find('Name').text();
$(this).find('Name').each(function(){
var value = $(this).text();
select.append("<option class='ddindent' value='"+ value +"'>"+value+"</option>");
});
});
}
});
});
but it gives the below error in the console window :
Access to XMLHttpRequest at 'http://localhost:8080/geoserver/wfs?request=getCapabilities' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.