【发布时间】:2014-04-05 03:40:35
【问题描述】:
我是 ajax/javascript/jquery 的新手,正在尝试将页面呈现到包含我的表单的页面上。我正在渲染它,但是当它渲染时,它会转到我的表单页面,除了它实际加载页面,忽略布局并删除我的表单。
这是我的控制器代码:
<?php
class PlayersController extends AppController{
public $components = array('RequestHandler');
public function listall() {
$this->set ( 'players', $this->Player->find ( 'all' ) );
}
public function index() {
if (!empty($this->request->data)) {
$this->Player->create();
if ($this->Player->save ( $this->request->data )){
$this->set ( 'players', $this->Player->find ( 'all' ));
$this->render('listall', 'ajax');
}
}
}
}?>
这是我对表单的看法:
<?php
echo $this->Form->create();
echo $this->Form->input('name',array('id' => 'name'));
echo $this->Js->submit('Save', array(
'before' => $this->Js->get('#inprogress')->effect('fadeIn'),
'success' => $this->Js->get('#inprogress')->effect('fadeOut'),
'update' => '#success'
));
echo $this->Form->submit('normal submit');
echo $this->Form->end();
?>
<div id="inprogress" style="display: none;background-color:
lightblue">Saving in progress...</div>
这是我要渲染的视图:
<p style="background-color: lightblue">Players</p>
<table>
<tr>
<td>Name</td>
</>tr
<?php foreach ($players as $players): ?>
<tr>
<td><?php echo h($players['Player']['name']); ?> </td>
</tr>
<?php endforeach; ?>
</table>
这就是我在布局中引入 jquery 的内容:
echo $this->Html->script('jquery-2.1.0.min');
echo $this->fetch('meta');
echo $this-Js->writeBuffer(array('cache' => TRUE));
我一直在试图弄清楚如何在视图索引中实际呈现视图列表而不实际重新加载页面。现在很吃亏。
【问题讨论】:
标签: javascript php jquery ajax cakephp