Hi all,
I am trying to populate a select box (cities related to a state) using the $.ajax method of jquery.
I wrote the following in my php script
$('#cmbState').change(function(){
$('#cmbCity').children().remove();
$.ajax({
type: "POST",
url: "../include/ajax.php",
data: "option=getCitiesList&stateid="+$(this).val()+"",
dataType: "json",
complete: function(response){
'what should I write in here ..?'
},
beforeSend: function(){$('#cmbCity').addClass('show_loading_in_center')},
success: function(){$('#cmbCity').removeClass('show_loading_in_center')}
});
});
and in the file 'ajax.php' (file where the query is sent for getting the realted cities) I did
$i=0;
foreach($cities as $city)
{
$response[$i]['id'] = $city['pk_cityid'];
$response[$i]['name'] = $city['name'];
$i++;
}
echo json_encode($response);
Now the response comes as XMLHTTPResponse object. How shall I populate the response into cities selectbox.?
Please help, I am really stuck over here.
Thanks