I have a dropdown that updates the ajax field. Everything works fine, but the ajax field is not populated with page load data. How can I force update the ajax field when the page loads?
This is a drop down list:
echo CHtml::dropDownList('category_selection_code', '', $cat_list_data,
array('style'=>'width:400px',
'ajax' =>
array(
'type'=>'POST',
'url'=>CController::createUrl('articles/GetContentFields'),
'update'=>'#ExtraContentFields',
)
)
);
* UPDATE
I found a solution that works for me:
$(document).ready(function(){
$.ajax({
type: 'POST',
data: {category_selection_code: $('#category_selection_code').val()},
url: '<?php echo CController::createUrl('articles/GetContentFields'); ?>',
success: function(data){
$('#ExtraContentFields').html(data)
}
})
})
The controller for handling ajax articles / GetContentFields expects category_selection_code in the $ _POST array. And we need to install it in the data section of the ajax part:
: { category_selection_code : $ ('# category_selection_code'). val ()},
Thnx is all for reference.
source
share