I am building an app in CakePHP and I have a jquery dialog window and every time the user opens it I want to perform a jquery request that will populate the content with the result of the request.
I have an js file that is in the webroot/js folder, with the following script:
$.ajax({
url:'/projects/getAssets',
type:"POST",
data:assetData,
//dataType:'text',
update: '#assetManagerContent'
});
In my controller file (ProjectsController) I have the following function:
function getAssets($id = null) {
// Fill select form field after Ajax request.
if(!empty($this->data)){
$this->set('assetsFilter',
$this->Project->Asset->find('list',
array(
'conditions' => array(
'Asset.project_id' => '23'
)
)
)
);
$this->render('elements/assets', 'ajax');
}
}
And finally I have the view (elements/assets):
<?php $assetsFilter = $this->requestAction('projects/getAssets'); ?>
<?php foreach($assetsFilter as $assetFilter): ?>
<div class="assetManager-asset">
<div class="thumb"></div>
<div class="label-name"><?php echo $assetFilter['AssetType']['type'] ?></div>
<div class="label-date"><?php echo $assetFilter['Asset']['layer'] ?></div>
<?php //echo $assetFilter['Asset']['id'] ?>
</div>
<?php endforeach; ?>
When the user opens the dialog the ajax request is triggered but nothing seems to happen in the #assetManagerContent div.
I hope someone can tell me what I am doing wrong
As far as I know, there is no
updateoption in the jQuery ajax api. Instead, you should add the success callback and populate the data there: