2014-08-31 70 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