我有一个带有ajax按钮的CGriview,但当我点击按钮时,页面刷新并且没有向我的动作发送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 :(得分: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
哪个行动?
答案 1 :(得分: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
}'
),
答案 2 :(得分: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!!