If you're getting Error 404 not found so the controller or the action you're calling doesn't exists.
First : Looks like the url you're using in the Ajax request is wrong.
It should be :
url : '/advert/loadsubcategory',
And not :
url : '/advert/loadsubcategory/'
It shouldn't be a / at the end of the url.
Second : To avoid any error in your url, you can get the exact url inside your Zend view
file and then pass it as a parameter to your dependentDropDown function like this :
<script type="text/javascript">
$(document).ready(function() {
var ajax_url = "<?= $this->url($this->route, array('controller'=>'advert', 'action'=>'loadsubcategory'));?>";
dependentDropDown(source_id, target_id, ajax_url);
});
</script>
Assuming that you have a dependentDropDown function which looks like this :
dependentDropDown = function(source,target,url){
$('#'+source).change(function() {
$.ajax({
type: 'POST',
async: true,
url: url,
cache: true,
dataType: 'json',
data: {id: $('#'+source).val() },
success: function(data){
//success function, populating the target with data
},
error: function(jqXHR,textStatus,errorThrown){
var error = $.parseJSON(jqXHR.responseText);
var content = error.content;
console.log(content.message);
if(content.display_exceptions)
console.log(content.exception.xdebug_message);
},
});
});
}
And inside your AdvertController :
public function loadsubcategoryAction(){
$request = $this->getRequest();
if ($request->isPost())
{
$categoryID= $request->getPost('id', null);
$data = new JsonModel(array(
'success' => true,
'results' =>$subcategories, //<---- your data to return
));
return $data;
}
}