I've got 2 select elements in my code. One for US states (#us_state) and second for cities (#city_name). When I choose a "state" the second select element must contain only that cities which exists in selected state. I use ajax, I done the request and got the response. Response format is id:name {"26332":"Abbott Park","27350":"Addieville", ...}
. Now I want to add the response to option elements and append it to select element with #city_name id
. But I don't know how to achieve this result. <option value="key">value</option>
$('#us_state').bind('change', function() {
var projectId = $("#inputtitle").val();
var stateId = $(this).val();
var arrayData = {"projectId": projectId, "stateId":stateId};
$.ajax({
type: "GET",
url: "/bidboldly/projects/editproject/",
data: arrayData,
success : function(response) {
............
..........
},
error: function(){
alert("error");
}
})
});