javascript - How to access an array in j-query returned by php script -
i want access array in j-query returned php script via ajax call
ajax call getting result 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 in pending group"); $('#meter_group_name').attr('selectedindex',0); } $("select#meter_number").html(data["option"]); } });
response of ajax call 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 option field store
<select name="meter_numbers" id="meter_number"></select>
how check data["exists"]==1 in jquery code , populate select in html data["option"]?
you can use json_encode() here like,
in js
ajax function
add type:
$.ajax({ url:'', data:'', datatype:'json',//add line
refer datatype in ajax
in php script use json_encode function
like,
echo json_encode($yourarray); return;
Comments
Post a Comment