Den*_*G B 19
你可以制作像ajax这样的链接
Html::a('Your Link name','controller/action', [
'title' => Yii::t('yii', 'Close'),
'onclick'=>"$('#close').dialog('open');//for jui dialog in my page
$.ajax({
type :'POST',
cache : false,
url : 'controller/action',
success : function(response) {
$('#close').html(response);
}
});return false;",
]);
Run Code Online (Sandbox Code Playgroud)
Nin*_*Cat 10
来自:http://www.yiiframework.com/wiki/665/overcoming-removal-of-client-helpers-eg-ajaxlink-and-clientscript-in-yii-2-0/
您可以轻松地创建所需的所有客户端帮助程序并将其组合到单独的JS文件中.将新的AssetBundle和AssetManager功能与Yii2中的View对象一起使用,以管理这些资产及其加载方式.
或者,可以在视图中在运行时注册内联资源(JS/CSS).例如,您可以使用内联javascript清楚地模拟ajaxLink功能.但是,如果可以将客户端代码(JS/CSS)合并到单独的JS/CSS文件中并通过AssetBundle加载,则建议使用它.请注意,不再需要CClientScript:
$script = <<< JS
$('#el').on('click', function(e) {
$.ajax({
url: '/path/to/action',
data: {id: '<id>', 'other': '<other>'},
success: function(data) {
// process data
}
});
});
JS;
$this->registerJs($script, $position);
// where $position can be View::POS_READY (the default),
// or View::POS_HEAD, View::POS_BEGIN, View::POS_END
Run Code Online (Sandbox Code Playgroud)