To implement AJAX functionality in your web application, you can create a call to a controller action that will initialize your widget and execute its JavaScript functions. Here's an example:
//@app/widget/Widget1
class Widget1 extends \yii\base\Widget
{
public function run()
{
echo new JsExpression('function(){ alert("hello,world") }');
}
}
//@app/controllers/SomeController
public function actionSomeaction()
{
return Widget1::widget();
}
You can then trigger this action from an AJAX function handling an 'onClick' event using jQuery, for instance:
<script>
$.post('/some/someaction',function(response){
response();
});
</script>