cakephp ajax更新div不会出现

时间:2015-12-08 09:44:26

标签: javascript php jquery ajax cakephp

我想创建一个基本的网络应用程序,将输入的数据提交到数据库,并且还更新div以显示保存到数据库的数据,而无需使用ajax重新加载整个页面请帮我解决这个问题。

h ere是我的消息/ index.ctp

<div ="success"> </div>
<?php
echo $this->Html->script('jquery', FALSE); 

echo $this->Form->create();
echo $this->Form->input('name');
echo $this->Form->input('email');
echo $this->Form->input('message');
echo $this->Js->submit('Send',array('update' => '#success'));
echo $this->Form->end();
?>

<div id="sending" style="display:none; background-color:lightgreen"> </div> 

和我的MessagesController.php

<?php

class MessagesController extends AppController
{
    public $helpers = array('Js');
    public $components = array('RequestHandler');

    public function index()
    {
        if(!empty ($this->data))
        {
            if($this->Message->save($this->data))
            {
                if ($this->RequestHandler->isAjax())
                    $this->render('view', ajax);
                else
                {
                $this->Session->setFlash('Message Sent!');
                $this->redirect(array('action' => 'index'));
                }
            }
        }
    }

    public function view()
    {   
            $this->loadModel('Message');
            $data = $this->Message->find('all');
            $this->set('dbdata',$data);

    }
}

我的消息/ view.ctp

<table>
    <tr>
        <td>Name</td>
        <td>Email</td>
        <td>Message</td>
    </tr>
<?php foreach ($dbdata as $name) : ?>
    <tr>
        <td><?php echo $name['Message']['name'] ?> </td>
        <td><?php echo $name['Message']['email'] ?> </td>
        <td><?php echo $name['Message']['message'] ?> </td>
    </tr>

<?php endforeach; ?>

0 个答案:

没有答案