douyeyan0650
2013-03-13 10:14
浏览 21
已采纳

如何用jquery调用cakephp动作?

I just want to call a cakephp action with jquery clicking on checkbox. I just want to refresh the current page by I want to use $.get because I want to send others variables to the action. I tried the following code :

HTML code :

<?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 code :

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

Does anyone can help me ?

Thanks a lot in advance for your help.

图片转代码服务由CSDN问答提供 功能建议

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

HTML代码:

 &lt;?php $ chkOpt = array('pertinence'=&gt; $  pert,'onClick'=&gt;'refresh_current_page()','id'=&gt;'matchCoche');  ?&gt; 
 
&lt; td class =“check-column”&gt;&lt;?= $ form-&gt;复选框($ waiting ['ArgusWaitingsMobilesPrice'] ['品牌']。';'。$ waiting ['  ArgusWaitingsMobilesPrice'] ['mobile']。';'。$ waiting ['search'] ['RefAvatar'] ['mobile_id'],$ chkOpt)?&gt;&lt; / td&gt; 
   
 
 

Javascript代码:

 &lt; script type =“text / javascript”&gt; 
 function refresh_current_page(){
 $('  #matchCoche')。ready(function(){
 $ .get(“&lt;?php echo $ this-&gt; here?&gt;”); 
}); 
} 
&lt; / script&gt;  
   
 
 

有没有人可以帮助我?

非常感谢您的帮助。 < / DIV>

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • duankang5285 2013-03-13 10:17
    已采纳

    Better use click event. Dont mix it with HTML :)

    $(document).ready(function(){
        $('#matchCoche').click(function(){
              $.get("http://"+ document.domain +"/yourController/yourAction/param1/param2/");
        });
    });
    

    Anyway, if you just want to call the page again with other parameters, why dont you use a normal HTML link for it?

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongyuan9892 2013-03-13 11:04

    As mentioned in the previous answer you're better off just using a regular link. You can send additional variable via named parameters:

    <a href="/controller/action/id/variable1:value1/variable2:value2" />link</a>
    
    评论
    解决 无用
    打赏 举报
  • dongri1989 2013-03-13 11:07

    The relevant documentation can be found at :

    http://book.cakephp.org/view/1096/Using-Helpers for how to include non-default helpers http://book.cakephp.org/view/1589/script for using the 1.3.x Html helper to include scripts http://book.cakephp.org/view/349/Methods for using the 1.2.x Javascript helper

    http://book.cakephp.org/1.3/en/The-Manual/Core-Helpers/Js.html

    评论
    解决 无用
    打赏 举报
  • dongzi0850 2013-03-13 14:05

    I always use Html helper to make the url, keeps me from trouble.

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

    This assumes you have 'Js' helper loaded and have:

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

    in your layout before the closing body tag

    I find it convenient to use Js->buffer. Js->writeBuffer will collect all the snippets from the buffer and take care of $(document).ready function.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题