I want to access an array in J-query returned by PHP script via Ajax call
Ajax call for getting result from PHP script:
$.ajax({
url: "http://localhost/WCPM/index.php/demand/check_demand_status",
type: 'GET',
cache: true,
data: {
Meter_Group_Name: $(this).val()
},
success: function(data) {
if(data["exists"]==1){
alert("Request already in pending for this Group");
$('#Meter_Group_Name').attr('selectedIndex',0);
}
$("select#meter_number").html(data["option"]);
}
});
Response of Ajax Call from Php script:
Array
(
[exists] => 1
[option] => <option value=''>Please Select Meter</option>
<option value='5'>222000</option>
<option value='6'>101010</option><option value='7'>34500A</option>
<option value='13'>A00001</option><option value='14'>A11149</option>
<option value='15'>000123</option><option value='16'>A00003</option>
<option value='17'>A00002</option>
)
Html Select Tag where option field to be store
<select name="Meter_Numbers" id="meter_number"></select>
How to check data["exists"]==1 in jquery code and populate select in html with data["option"]?