PHP
public function stateSearchAction()
{
$country = $this->getRequest()->getParam('code');
$collection = Mage::getModel('directory/region')->getCollection()
->addFieldToFilter('country_id', $country)->getData();
$this->getResponse()->clearHeaders()->setHeader('Content-type', 'application/json');
$this->getResponse()->setBody(Zend_Json::encode($collection));
}
JS
document.observe('dom:loaded', function () {
$('country').observe('change', function () {
var country = this.value;
new Ajax.Request('/perfil-fornecedor/index/stateSearch', {
method: 'get',
parameters: {code: country},
onSuccess: function(response) {
var states = response.responseJSON;
$('state').select('option').invoke('remove');
if( states.length > 0) {
for(var i = 0; i <= states.length;i++ ) {
console.log(states[i].code, states[i].default_name);
$('state').insert(new Element('option', {value: states[i].code}).update(states[i].default_name));
}
}
}
});
})
});