php - 如何使用 jquery 调用 cakephp 操作?

标签 php javascript cakephp get

我只想用 jquery 单击复选框来调用 cakephp 操作。我只想使用 $.get 刷新当前页面,因为我想将其他变量发送到操作。我尝试了以下代码:

HTML 代码:

<?php $chkOpt = array('pertinence' => $pert, 'onClick' => 'refresh_current_page()', 'id' => 'matchCoche'); ?>

<td class="check-column"><?= $form->checkbox($waiting['ArgusWaitingsMobilesPrice']['brand'] . ';' . $waiting['ArgusWaitingsMobilesPrice']['mobile'] . ';' . $waiting['search']['RefAvatar']['mobile_id'], $chkOpt) ?></td>

Javascript代码:

<script type="text/javascript">
            function refresh_current_page() {
                $('#matchCoche').ready(function() {
                                $.get("<?php echo $this->here ?>");
                });
            }
        </script>

有人可以帮助我吗?

预先非常感谢您的帮助。

最佳答案

我总是使用 Html 助手来制作 url,这样我就不会遇到麻烦。

<?php 
$this->Js->buffer('
    $(document).ready(function(){
        $('#matchCoche').click(function(){
              $.get("' . $this->Html->url( array('controller' => 'your_controller', 'action' => 'your_action', 'param1', 'param2') ) . '");
        });
    });
'); 

?>

这假设您已加载“Js”助手并具有:

<?php echo $this->Js->writeBuffer(); ?>

在布局中结束正文标记之前

我发现使用Js->buffer很方便。 Js->writeBuffer 将从缓冲区收集所有片段并处理 $(document).ready 函数。

关于php - 如何使用 jquery 调用 cakephp 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15382377/

相关文章:

database - cakephp 数据库 session 过期字段?

android - 将 Android 应用程序与 CakePhp 网站连接

php - 基本的 php 正则表达式问题

javascript - Ajax、Php-回发仅适用于 Firefox

php http header

javascript - 使用 <a href> 打开特定选项卡并保存到 localStorage

php - 单个 PHP 上的多种表单

javascript - Angular JS选择菜单项出现两次

javascript - 在javascript中使用时间延迟函数

php - CakePHP 2.4 使用 bcrypt 登录失败