2014-08-31 72 views
0

我CGriview使用Ajax按鈕,但是當我上的按鈕,頁面刷新點擊犯規發送AJAX參數到我的行動,我的代碼是這樣的:阿賈克斯按鈕不起作用

enter code here 
array(
         'class'=>'CButtonColumn', 
         'template'=>'{reset}', 
         'buttons'=>array(
          'reset'=>array(
           'label'=>'reset', 
         'url'=>'Yii::app()->controller->createUrl("place/viewHallModal/",array("row"=>"1"))', 
           'options'=>array(
            'class' => 'btn', 
             'ajax'=>array(
              'type'=>'post', 
              'url'=>'js:$(this).attr("href")', 
              'update'=>'#section-update', 
              'success' =>'js:function(data) {alert("suc");}' 
             )), 
          ), 
         ), 

       ), 

回答

0

我還沒有超過50個評論的評論,所以我只能用回答這個問題。

jQuery,你可以這樣寫AJAX功能類似這樣的

... 
$.ajax({ 
    type: 'post', 
    url: 'your_url_will_goes_here', 
    cache: false, // or true 
    data: { 
     'your_data': $variable, 
     'your_data1': $variable1, 
    }, 
    success: function(data){ 
     alert("success !"); 
}); 
.... 

,但我看不到你的data AJAX功能。 那麼你想把哪個data傳遞給你的動作?

0

在文檔

'buttonID' => array 
(
    'label'=>'...',  //Text label of the button. 
    'url'=>'...',  //A PHP expression for generating the URL of the button. 
    'imageUrl'=>'...', //Image URL of the button. 
    'options'=>array(), //HTML options for the button tag. 
    'click'=>'...',  //A JS function to be invoked when the button is clicked. 
    'visible'=>'...', //A PHP expression for determining whether the button is visible. 
) 

你的按鈕將是:

'reset'=>array(
      'label'=>'reset', 
      'url'=>'#', 
      'click'=>'js:function(){ 
       // here write your function 
      }' 
     ), 
+0

我改變這樣我的代碼,但它的按鈕點擊後dosent !!頁面刷新工作 – 2014-09-01 04:50:37

+0

可能不知道點擊事件。請嘗試: js:function(e){ e.preventDefault(); //現在寫所有你需要的 } – 2014-09-01 08:15:08

0
I change my code like this,but dosent work yet and the page wes refreshed!! 
.... 
array(
         'class'=>'CButtonColumn', 
         'template'=>'{reset}', 
         'buttons'=>array(
          'reset'=>array(
           'label'=>'reset', 
'url'=>'Yii::app()->controller->createUrl("place/viewHallModal/")', 
           'click'=>'js:function(){ 
             alert("click"); 
             $.ajax({ 
              type: "post", 
              url: "js:$(this).attr("+"href"+")", 
              cache: false, // or true 
              data: { 
               "your_data": "a", 
               "your_data1": "b", 
              }, 
              success: function(data){ 
               alert("success !"); 
              } 
             }); 
           }', 
.... 

my function in the click event was run and show me the alert but it replace above url in the href of tag <a href=""></a> and when i click on the button go to that address!! 
+0

我刪除了url並輸入了ajax manualy的url,它工作。謝謝。 – 2014-09-01 05:10:37