I want to show JSON data to HTML select option but the problem is data is inside another array
HTML code
<select id="ExchCode" class="form-control" name="ExchCode" autocomplete="off" required>
<option id="exchange-house" value=""></option>
</select>
JSON Code result from Ajax request
{
"status": "200",
"success": true,
"mesg": "data found",
"data": [
{
"exchangeCode": "0",
"exchangeName": "-SELECT EXCHANGE HOUSE-"
},
{
"exchangeCode": "24NME",
"exchangeName": "PAYPAL"
},
{
"exchangeCode": "AAM112",
"exchangeName": "AL AHALIA "
},
{
"exchangeCode": "ZEN042",
"exchangeName": "ZENJ EXCHANGE CO. W.L.L,"
}
]
}
My jquery to populate the data from ajax request
$(document).ready(function() {
//Make an Ajax request to a PHP script called get-exchange-house.php
$.ajax({
url: 'fetch-data.php',
type: 'get',
dataType: "json",
success: function(response){
//console.log(response);
$.each(response.data, function(data.exchangeCode, data.exchangeName){
//Use the Option()
var option = new Option(exchangeCode, exchangeName);
$(option).html(exchangeName);
//Append the option to our Select element.
$("#ExchCode").append(option);
});
//Change the text of the default "exchange-house" option.
$('#exchange-house').text('Select Exchange House');
}
});
});