I have list of json results but cant get into select html tried the following code
Json ouput: jquery loop on Json data using $.each
{"Eua":"Eua","Ha'apai":"Ha'apai","Niuas":"Niuas","Tongatapu":"Tongatapu","Vava'u":"Vava'u"}
success: function(result){
console.log(data);
var data = jQuery.parseJSON(result);
jQuery.each(data,function(key, value)
{ //jQuery("#state").html();
console.log(key);
jQuery("#state").html('<option>'+value+'</option>');
})
Using the instruction
jQuery("#state").html(...)
would replace the previous option with new one, so you will always get only one option, which is the last Json value.
You should use
jQuery("#state").append(...)
This instruction would append an option to the select dropdown, remaining the previous options in place.