I have the following jQuery code. I am able to get the following data from server [{"value":"1","label":"xyz"}, {"value":"2","label":"abc"}]
. How do I iterate over this and fill a select box with id=combobox
$.ajax({
type: 'POST',
url: "<s:url value="/ajaxMethod.action"/>",
data:$("#locid").serialize(),
success: function(data) {
alert(data.msg);
//NEED TO ITERATE data.msg AND FILL A DROP DOWN
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
},
dataType: "json"
});
Also what is the difference between using .ajax
and $.getJSON
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…