2013-03-13 56 views
2

我只想用jquery點擊複選框來調用cakephp動作。我只想刷新當前頁面,我希望使用$ .get,因爲我想將其他變量發送到該操作。我嘗試下面的代碼:如何用jquery調用cakephp動作?

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> 

有誰可以幫我嗎?

非常感謝您的幫助。

回答

1

更好地使用click事件。不要用HTML :)

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

混合它無論如何,如果你只是想和其他參數再次調用頁面,你爲什麼不使用普通的HTML鏈接呢?

0

正如前面的回答中所提到的,您最好只使用常規鏈接。

<a href="/controller/action/id/variable1:value1/variable2:value2" />link</a> 
2

我總是使用HTML助手使網址,讓我免受麻煩。

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

?> 

這裏假設你有「的js」助手加載,並且有:結束標記

我覺得很方便地使用Js->緩衝器之前在佈局

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

。 Js-> writeBuffer將收集緩衝區中的所有片段,並處理$(document).ready函數。