我只想用 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/