CakePHP2系 の更新処理を Ajax

http://blog.xao.jp/blog/cakephp/one-of-the-simple-way-for-using-ajax-in-cakephp/
http://ustom.daa.jp/blog/2012/11/js%E3%83%98%E3%83%AB%E3%83%91%E3%83%BC%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6%E3%80%80%E3%81%9D%E3%81%AE%EF%BC%91%EF%BD%9Ccakephp2/

test_controller.php

[php]
class TestController extends AppController {

var $name = ‘Test’;
var $helpers = array(‘Form’, ‘Js’=>array(‘jquery’) );

function index() {
$this->Test->recursive = 0;
$this->set(‘tests’, $this->paginate());
}

function test() {
}
}[/php]
test.ctp
[php]
<?php
$this->Html->script(‘jquery’,array(‘inline’=>false));

$this->Js->get(‘#btn’);
$request = $this->Js->request(
array(
‘action’ => ‘index’, //indexを表示
‘controller’ => ‘test’ //textコントローラーの
),
array(
‘method’ => ‘get’,
‘sync’ => true,
‘update’ => ‘#data’, //id="data"に表示させるよ
‘success’ => "alert(‘get data!!!’);"
)
);
$this->Js->event(‘click’,$request);
echo $this->Js->writeBuffer(array(‘inline’=>false));
?>

<div>
<div id="data"></div> //ここにindexを表示させるよ
<input id="btn" type="button" value="取得" />

</div>
[/php]

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です