CakePHP 2.x を使用しています。ページ全体の更新ではなく、jquery ui からのモーダル ダイアログが閉じられた後 (送信後)、ページのドロップダウンを新しい値で更新したいと考えています。どうすればそれを達成できますか?
私の ArticlesController.php で
public function admin_add() {
//setting active link
$this->set('active', 'new_article');
if ($this->request->is('post')) {
$this->request->data['Article']['posted'] = date('Y-m-d H:i:s');
$this->Article->create();
if ($this->Article->save($this->request->data)) {
$this->Session->setFlash(__('The article has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The article could not be saved. Please, try again.'));
}
}
$categories = $this->Article->Category->find('list');
$this->set(compact('categories'));
}
そして私のビューページ(admin_add.php)
<div>
<?php echo $this->Form->create('Article');?>
<?php
echo $this->Form->input('title');
echo $this->Form->input('author');
//THIS IS THE DROPDOWN PART
echo $this->Form->input('category_id');
//THIS IS THE PART FOR CALLING THE MODAL DIALOG TO ADD A NEW CATEGORY
echo '<div class="addNewCategory">';
echo 'add';
echo '</div>';
?>
<?php echo $this->Form->end(__('Submit'));?>
</div>
<!-- Modal Dialog for Adding New Category (THIS IS HIDDEN UNTIL GET CALLED AS MODAL DIALOG)-->
<div class="dialog-form" title='Create new Category'>
<?php echo $this->Form->create('Category');?>
<?php
echo $this->Form->input('name');
?>
<?php echo $this->Form->end(__('Submit'));?>
</div>
<script type="text/javascript">
$('.dialog-form').dialog({
autoOpen: false,
title: 'New Category',
modal: true,
height: 300,
width: 350,
close: function() {
}
});
$('.addNewCategory').click(function() {
$('.dialog-form').dialog('open');
});
$('.dialog-form .submit').click(function(e) {
var value = document.getElementById('CategoryName').value;
var data = {'data[Category][name]':value};
e.preventDefault();
$.ajax({
type:"POST",
url: "<?php echo $this->Html->url(array('controller' => 'categories', 'action' => 'addmodal', 'admin' => TRUE)); ?>",
data: data,
success: function() {
$('.dialog-form').dialog('close');
//WHAT SHOULD I DO IN HERE AFTER THE DIALOG CLOSED TO UPDATE THE DROPDOWN OR IF ITS NOT IN HERE PLEASE LET ME KNOW THE SOLUTION
}
})
});
</script>
上記は、コントローラーとビュー、およびスクリプトのコードの一部です。大文字のコメントは私の説明です。ありがとうございました